if statement not working

Hello ! Im working my way through the programming: principles and practices using c++ and I've come across a problem a problem in the chapter 3 drill. The task is to design a letter that the user is writing to a friend after saying hello etc i have to modify the program to include two if statements if the user inputs that the sex of their friend is m (male) you have the program has to say tell him to call me. if the user inputs f (female) you have to get the program to say get her to call me. Here is the code, could anyone tell me where I'm going wrong? I'm getting the error on line 22 that 'm' wasn't declared in this scope and on line 26 I'm getting the error that f wasn't declared in this scope. Any help is much appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Chapter 3 drill

#include <iostream>
using namespace std;

int main (){
        cout << "Enter the name of the person you want to write to ";
        string first_name;
        cin >> first_name;
        cout << "Dear " << first_name << "," <<"\n";
        cout << "           Whats happin lad, how are you keeping? Im living in derry now\n\n "
             << "enter the name of your friend you haven't seen:\n";
        string friends_name;
        cin  >> friends_name;
        cout << "Im fine, but i haven't seen " << friends_name << " in ages!\n\n";

        char friends_sex = 0;

        cout << "press m if your friend is male or f if your friend is female \n\n";
        cin >> friends_sex;

        if (friends_sex = m)

        cout << "If you see " << friends_name << " please ask him to call me!";

        if (friends_sex = f)

        cout << "If you see " << friends_name << " please ask her to call me!";
}
= is assignment.

You probably wanted ==, which is comparison.

EDIT: also, m is a variable named m, which you never made. Just like friends_sex is a variable named friends_sex.

If you want to compare against the literal character m and not a variable named m, you put the m in single quotes: friends_sex == 'm'
Last edited on
Legend, worked a treat ! Thanks!
Topic archived. No new replies allowed.