/* Filename: DebugArray.cpp Author: Br. David Carlson Date: January 12, 1998 Revised: June 27, 2000; August 17, 2001; January 23, 2003 This program prompts the user to enter integers into an array, where they are stored in backwards order from that in which they are entered. The list of numbers is then printed on the screen (in backwards order, of course, from the order in which they were entered). Note that this program is provided as part of a debugging exercise. Try tracing through the code with your debugger to see if you can find the logic error that is keeping the data from being printed in backwards order as desired. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include using namespace std; const int MAX = 6; int count; void LoadArray(int a[]); void PrintArray(int a[]); int main(void) { int num[MAX]; count = MAX; LoadArray(num); PrintArray(num); return 0; } /* Given: Task: Return: */ void LoadArray(int a[]) { for (count = MAX - 1; count >= 0; count--) { cout << "Enter an integer: " ; cin >> a[count]; } } /* Given: Task: Return: */ void PrintArray(int a[]) { int m; cout << "The data in the array at the indices shown in the left column is:" << endl; for (m = 0; m < count; m++) cout << m << ": " << a[m] << endl; }