Please read my thread, need help

Hello,

I am writing a program in C++ using VS 2010

the program should do the following

"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;


I am stuck in No. 5

How are you stuck? You seem to have implemented No.5 already
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
if (x >= 'a' && x <= 'm');

Remove the semicolon ; at the end of the if condition.
I don't know if it's Ok.

the other half of the question is to find.

"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'.
it didn't work

by the way mine worked but not sure if right or not
what didn't work? How do I know what you tried :P
finally I figured it out it was a mess
st4

didn't get it
ignore them. They are one of the spammers that keep appearing on this site.
Anyway guys thanks for any help
Topic archived. No new replies allowed.