A problem with if else statements

This is meant to be a simple program designed to write a quick "happy birthday" email to someone. It seems like there is a problem with the if, else if and else statements. Please ignore the simple_error(); statements. They are not the issue here. Many thanks in advance - I just can't figure this out!

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "std_lib_facilities.h"

string first_name;
int age;
char spouse;
string spouse2;
string grammar;

int main()
{
     grammar = "s y";
     cout << "\nPlease enter your name of the person you wish to write to (followed by 'enter'):\n";
     cin >> first_name;             // read characters into first_name
     cout << "\nPlease enter the age of the person you wish to write to (followed by 'enter'):\n\n";
     cin >> age;

        if (age <= 0 || age > 110) {
            simple_error("\nYou're Kidding! Right?!\n");
        }

     cout << "\nPlease enter the gender of the person's spouse (write 'm' for male, 'f' for female and 'p' for unmarried followed by 'enter'):\n\n";
     cin >> spouse;
        if (spouse != 'm' && spouse != 'f' && spouse != 'p') {
            simple_error("\nUm ... Try Again?\n");
        }


        if (spouse = 'm') {
            spouse2 = "your husband";
        }
        else if (spouse = 'f'){
            spouse2 = "your wife";
        }
        else {
            spouse2 = "your friends and family";
            grammar = " y";
        }
     cout << "\nDear " << first_name << ",\n";
     cout << "  I wanted to wish you a very happy birthday. I hope you have a great day.\n";
     cout << "You really deserve it!\n";
     cout << "I still can't believe your already " << age << " years old!\n";
     cout << "I hope " << spouse2 << " get" << grammar << "ou some great presents!\n" << endl;
     cout << "Yours Sincerely, \n\n\n";
     cout << MY NAME\n";

} 
Last edited on
You're using single equals signs instead of double on lines 28 and 31.
Last edited on
Thanks!
Topic archived. No new replies allowed.