• c++ help
    2 replies, posted
// ********************************************************************************* // Lab 12: reverse // Program reverse reads numbers into an array and prints them out in reverse order. // Timmy Moore, @02334414, 002 // December 09, 2010 // ********************************************************************************* // Program Reverse reads numbers into an array // and prints them out in reverse order. #include <iostream> #include <fstream> using namespace std; const int MAX = 10; int main () { int numbers[MAX]; ifstream inData; int value = 9; int index; inData.open("reverse.dat"); for (index = 0; index < MAX; index++) { inData >> numbers[MAX]; numbers[index] = numbers[value]; value --; } for (index = MAX - 1; index >= 0; index--) { cout << numbers[index] << endl; } return 0; } _________________________________________________________________________ this is the .dat file 99 88 77 66 55 44 33 22 11 0 _______________________________________________________________ it is supposed to print it in reverse order but im having a hard time knowing how to read it from the file then reversing it. my ouput just keeps giving me like -858993460 .... it says it 10 times then it askes me to abort it .. please help
Get rid of the whole "value" related stuff, then change the loop body to this: [code]inData >> numbers[index];[/code] Also, two things. I'm not sure what your assignment was, but they may have wanted use of recursion or some other method that doesn't require a max quantity of numbers. Also, there's a help thread for posts like this.
Thanks alot
Sorry, you need to Log In to post a reply to this thread.