For this assignment, I have to reverse whatever the user has input.
So, if the user were to input:
123456789
I have to make a program that outputs:
987654321
This is my code so far, but it's got a few.. 'quirks'(?) in it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i;
char score[10];
cout << "Enter anything you want reversed: " << endl;
for (i = 0; i < 10; i++)
{
cin.get(score[i]);
if (score[i] == '\n')
{
cout << "You have entered: " << endl;
for (i = 9; i >= 0; i--)
{
cout.put(score[i]);
}
}
}
}
|
First of all, I'm using get() and put() so that the program will read spaces the user has input. Also, the size of the array has to be 10.
However, if you compile this code, you'll notice that while it does reverse whatever I input, it'll sometimes give me some weird characters before showing me what I've input in reverse.
Also, once it's shown the input in reverse, the cursor will keep blinking instead of just ending the program.
Help, please?
These are the instructions:
1 2
|
You should limit the amount of data being stored in your array to 10 values. After
you read and store 10 or less values in your array from the terminal, ignore any other input.
|