Is there any way I can cin >> x; a number from 0 to 99 but have the single digits numbers input with a leading zero like 01 for 1 or 07 for 7. Then have a switch (x) case that will look like this { case 01: cout << "One ";break; etc... Or is 01, 02,... not accepted as an int.
If the user types (without the quotes): "000004" this will still be read into an integer as 4 and comparable against 4. Eg,
1 2 3 4 5
int x;
cin >> x;
switch( x ) {
case 4: // Catches "4", "04", "004", etc.
}
One thing you DO have to be careful about is that when programming, putting a leading zero in front of an integer causes the compiler to treat the value as octal rather than decimal, such that:
1 2 3 4 5 6
switch( x ) {
case 010: // This is actually decimal 8
break;
case 08: // This is a compile error since '8' is not a valid octal digit
break;
}
Thank you I was wondering why it was crashing. To answer your question I want the user to type in a # from 00 to 09. But I have the switch case print out the single digit.