Solved

Adding & Displaying Two Dimensional Array

Posted on 2011-03-15
4
420 Views
Last Modified: 2012-05-11
Can somebody tell me what I'm doing wrong?  I want to enter five start/finish times into a two-dimensional array, and get them to print out:
#include <iostream>
#include <stdlib.h>

using namespace std;
 
const int FINISH = 2;
const int START = 5;
 
void getData(int arr[][FINISH]);
void displayData(int arr[][FINISH]);

int i,j;
 
int main()
{
      int timeArray[START][FINISH];
 
      getData(timeArray);
      displayData(timeArray);
 
      cout << endl << endl << endl;

      system("PAUSE");
      return 0;
}

// used to prompt user to fill array with values
void getData(int arr[][FINISH])
{
      cout << "Enter 5 start/finish times." << endl
        << "One at a time when prompted: " << endl;

         cout << endl;

   for(int i = 0; i <= 4; i++)
   {
      cout << "Enter start[" << i + 1 << "]: ";
      cin >> arr[i][j];

	  for(int j = 0; j <= 0; j++)
		{
		  cout << "Enter finish[" << j + 1 << "]: ";
		  cin >> arr[i][j];
		}

      cout << endl;
   }
}// end getData()
 
// used to display array contents
void displayData(int arr[][FINISH])
{
	cout << endl << endl;
      for (int i = 0; i < START; i++)
      {
            for (int j = 0; j < FINISH; j++)
                  cout << arr[i][j] << " ";
            cout << endl;
      }
}// end displayData()

Open in new window


The "j" part is not counting properly, and it won't display properly...
0
Comment
Question by:Member_2_4213139
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 35138016
Why do you have this:

for(int j = 0; j <= 0; j++)
{
    cout << "Enter finish[" << j + 1 << "]: ";
    cin >> arr[i][j];
}

Open in new window


I would have expected to see this (where j had been initialized to zero):
cout << "Enter finish[" << j + 1 << "]: ";
cin >> arr[i][j + 1];

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 35138025
>> for(int j = 0; j <= 0; j++)

Is the upper bound correct here ? The loop would only iterate once.
0
 
LVL 4

Assisted Solution

by:parnasso
parnasso earned 250 total points
ID: 35138040
In the line 38 you are using the variable 'j', which has not been initialized either declared yet.
Get the i and j variables declaration out of the for statement and give it a try.
0
 

Author Closing Comment

by:Member_2_4213139
ID: 35138204
THANK YOU ALL!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 73
C Programming - If Statement 8 72
recursion example 16 111
How do I save this device context as a .bmp or a picture of some kind? 2 48
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now