flynnwallace
02-22-2001, 08:28 PM
I need to write a program that read integers from the user and will then write those numbers backwards.
Ex. You entered numbers 23 45 3445 56
The numbers backwards are 56 3445 45 23
I wanted to use arrays but was told not to...this is what I have so far
#include <iostream.h>
{void main()
{
const int SENTINEL = -1;
int number;
cout << "Enter numbers one at a time as requested." << endl;
cout << "When done, enter " << SENTINEL << " to stop." << endl;
cout << "Enter the first score: ";
cin >> number;
while (number != SENTINEL)
{
cout<< "Enter the next numbers." <<endl;
cin >> number;
}
//now what????
}
I cant for the life of me figure out what the algorithem should be to write the entered numbers in reverse. Is there a function that does this? Does anyone have any ideas.
Flynn
Ex. You entered numbers 23 45 3445 56
The numbers backwards are 56 3445 45 23
I wanted to use arrays but was told not to...this is what I have so far
#include <iostream.h>
{void main()
{
const int SENTINEL = -1;
int number;
cout << "Enter numbers one at a time as requested." << endl;
cout << "When done, enter " << SENTINEL << " to stop." << endl;
cout << "Enter the first score: ";
cin >> number;
while (number != SENTINEL)
{
cout<< "Enter the next numbers." <<endl;
cin >> number;
}
//now what????
}
I cant for the life of me figure out what the algorithem should be to write the entered numbers in reverse. Is there a function that does this? Does anyone have any ideas.
Flynn