I have some Visual Basic programing experience but I am new to C++ I am working on a homework assignment and I am not sure why my code is not working out. I am trying to write a program that changes numbers form 1 to one , 2 to two,... I have got it to work and limited the choices to 1-5 and got that part to work as well. The problem I am running into is that if I enter 21 on a line it reads it as 2- two and 1 one and does not give me the inappropate character entered line that I want I though using char instead of int would fix that but it did not. here is my code can anyone one tell me what I am doing wrong.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char number ;
cout << "enter the number between 1 and 5 to be switched."<< endl
<< "enter the EOF character to end input." << endl;
while ( (number = cin.get () ) != EOF ) {
switch ( number ) {
case '1': // number entered is a one
cout << "The number you entered was ONE.\n";
break;
case '2': // number two entered
cout << "The number you entered was TWO.\n";
break;
case '3': // number two entered
cout << "The number you entered was THREE.\n";
break;
case '4': // number two entered
cout << "The number you entered was FOUR.\n";
break;
case '5': // number two entered
cout << "The number you entered was FIVE.\n";
break;
case '\n': // ignore newlines,
case '\t': // tabs,
case ' ': // and spaces in input
break; // exit
default: //catch all other characters
cout << " Incorrect character entered."
<< " Enter a new number between 1 and 5." <<endl;
break;
} // ends switch
} // ends while
return 0; // indicates successful termination
} // ends main function
Thanks for any suggestions