Hi All
Please help me with the following code, it works fine when i enter
1234567890 but goes mad when i enter one more digit i.e 12345678901.
It keeps on looping and displays infinitely:-
"Invalid Input. Please try again.!!"
How can i fix/correct this?
Any help will be appreciated!
#include <iostream>
#include <cassert>
using namespace std;
int main( )
{
int aDigit[ 5 ];
cout << "Enter 5 digits, each on a new line." << endl;
cout << "Your digits must be between 0 and 9: " << endl;
for ( int i = 0; i < 5; )
{
cin >> aDigit[ i ];
if((aDigit[i] >= 0) && (aDigit[i] <= 9))
{
cout << "Thank you. That is accepted as number " << i+1 <<"." << endl;
i++;
}
else
{
cout << "Invalid Input. Please try again.!!" << endl;
}
}
cout << endl << "Digits in reverse order:" << endl;
for ( int j = 4; j >= 0; j-- )
{
cout << aDigit[ j ] << endl;
}
return 0;
}