Variable Initialization?

Hi all,

I am a beginner trying to become literate in C++ using the book written by the creator, Bjarne Stroustrup. I am trying to go through one of the examples and can't figure out what is wrong with my code.

Here is what I have:

1
2
3
4
5
6
7
8
9
10
11
12
cout << "Enter an m if friend is male and f is friend is female:\n";
	char friend_sex = 0;
	cin >> friend_sex;

if (friend_sex == m)
		cout << "  If you see " << friend_name << " please ask him to call me.\n";
	
else if (friend_sex == f)
		cout << " If you see " << friend_name << " please ask her to call me.\n";
	
else
		cout << " If you see " << friend_name << " pleae ask them to call me.\n";


The errors I'm getting are saying that "m" and "f" are undeclared indentifiers. I guess it thinks that "m" and "f" are int variables.
Last edited on
Yeah,

In lines 5 and 8, you must use literals(ie: putting it in single quotes-'m' and 'f')

HTH,
Aceix
m and f in lines 5 and 8 should be character literals. i.e. 'm' and 'f'.
line 5 and 8..

1
2
3
4
5
Wrong!
(friend_sex == m) 

Right
(friend_sex == 'm')
Last edited on
O wow, I'm dumb. Thanks.
Topic archived. No new replies allowed.