"1-prompt the user to input a lower case letter
2-try to input a lower case letter
3-c&d (complain and die) if the input fails
4-c&d if the input isn’t a lower case letter
5-Tell the user whether his letter is in the first half of the alphabet (a-m) or the second half(n-z)"
and here is what I have done so far,
1 2 3 4 5 6 7 8 9 10 11 12 13 14
char x;
cout <<"Give me a lower case letter: ";
cin >> x;
if( !cin ) die( "Invalid input" );
if( x < 'a' || x > 'z' ) die( "That's not in the range of lower case letters" );
if (x >= 'a' && x <= 'm');
cout <<"That is in the first half of the alphabet " << x <<endl;
else
cout <<"That is in the second half of the alphabet " << x <<endl;
Error 3 error C2181: illegal else without matching if c:\documents and settings\fadi sheikh elias\my documents\visual studio 2010\projects\labhw\labhw.cpp 25 1 LabHw
"prompt the user to input a digit
try to input the digit into a char variable (not an unsigned variable)
c&d if the input fails
c&d if the char isn’t a digit
output the cube of the number the digit represents"
I am not sure if I answered it right
1 2 3 4 5 6 7 8 9 10 11
int y;
cout <<"Input digit: ";
cin >> y;
y = static_cast<char>(y);
if (!cin) die("input fails");
if ( y > 6e15 ) die("out of range");
cout << y <<"cubed is " << y*y*y <<endl;
try to input the digit into a char variable (not an unsigned variable)
Look at line 1. Notice have you have int instead of char?
line 6 not sure what you are trying to do. Think you have it backwards. Also it should probably be after validating input.
line 9 it doesn't ask if it is out of range it asks if the character is not a digit. eg y < '0' or y > '9'.