Hi, the reason when you enter 10, and it states you enter 1, is because you are using char instead int. Using char, it reads the first character of the input, for this case, the first character for '10' is '1'.
Any reason not using int? Simply change it to int and it solves all the problem. :)
Below is the code after changing it to int. Hope this helps!!!
int main()
{
int number; // "char" is used instead of "int"
cout << "Please enter a number from 1 through 10: \n";
cin >> number;
// Use switch statement
switch (number)
{
case (1) : cout << "You entered I.\n";
break;
case (2) : cout << "You entered II.\n";
break;
case (3) : cout << "You entered III.\n";
break;
case (4) : cout << "You entered IV.\n";
break;
case (5) : cout << "You entered V.\n";
break;
case (6) : cout << "You entered VI.\n";
break;
case (7) : cout << "You entered VII.\n";
break;
case (8) : cout << "You entered VIII.\n";
break;
case (9) : cout << "You entered IX.\n";
break;
case (10) : cout << "You entered X.\n"; // Result says "You entered I"
break;
default: cout << "You did not enter a number from 1 through 10.\n"; //Input Validatition
}
system ("pause");
return 0;
}
I used "char" instead of "int" because it worked better. But after changing it back to INT AND surrounding my numbers with parenthesis instead of single quote marks, everything worked fine-even fixed my input validation.
Thanks a lot.
Note: I am learning on my own. This problem is from the book Starting out with C++ by Tony Gaddis. Chapter 4, problem #2.