If Statement [C++]

Hello!

I have recently started learning C++ using Programming: Principles and Practice Using C++ by Bjarne Stroustrup. Through out the book, there are many "Drill" problems that we must do before proceeding to the next chapter to ensure that we get the most out of the book. On those problems, the author suggests that we try our best to do them ourselves before asking for help but I think I have tried everything and none seem to work. I have no idea what I am doing wrong. The problem I am working on have 7 parts; I have done the first 3 with no problem then got stuck on the 4th part for over two hours, so I am really hoping that someone can help me with it. Note: I have only included problem 4 and the codes related to it which I think is enough to be able to point out what I am doing wrong, but just in case it is not you can see the image on this link to see previous codes http://s24.postimg.org/4lyayjfad/Screen_Shot_2015_11_04_at_10_06_41_PM.png

Problem: Declare a char viable called friend_sex and initialize its value to 0. Prompt the user to enter an m if the friend is male and an f if the friend is female. Asking the value entered to the variable friend_sex. Then use two if-statememnts to write the following:
If the friend is male, write "If you see friend_name please ask him to call me."
If the friend is female, write "If you see friend_name please ask her to call me."

The error I am receiving is what is in parenthesis after "if".

You help is greatly appreciated,
Sheedo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
inline void keep_window_open() { char ch; cin>>ch; }

int main()
{
    cout << "Enter an m if the friend you are asking about is a male and f if they are a 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.";
    if (friend_sex == f) cout << "If you see " << friend_name << " please ask her to call me.";
}
Last edited on
The letter 'm' as you have put it is an indentifier, for example it can denote a variable named m.

To compare to the letter 'm', put the 'm' in single quotes. Putting a letter in single quotes creates a value called a character litteral.
Last edited on
Perfect, thanks!
Topic archived. No new replies allowed.