Adding & Displaying Two Dimensional Array

Posted on 2011-03-15
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];
      cout << endl << endl << endl;

      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...
Question by:Member_2_4213139
LVL 75

Accepted Solution

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

LVL 53

Expert Comment

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

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

Assisted Solution

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.

Author Closing Comment

ID: 35138204

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
C# DataGridView_RowsAdded event not firing 1 74
passing data from one form to another form in c++ 27 79
gdb doesn't stop on breakpoint 2 67
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

816 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