Program doesn't just close?

Okay, so, I haven't worked with C++ in a very long time, so I figured I'd make a simple(Well, medium difficulty for me, since I don't know much about making functions.) The problem is that instead of closing out of the console window, it...well, doesn't close out of the console window. Here's the source code:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

string clarification;
string name;
string gender;

int naming();

int main()
{
    cout << "Hello world!" << endl;
    cout << "What kind of person are you?(Male/Female/Other)" << endl;

    gender = "male";

    while (gender == "male" || "female" || "other")
    {
    cin >> gender;
    if (gender == "male")
    {
        cout << "What's your name, mister?" << endl;
        naming();
    }
    else if (gender == "female")
    {
        cout << "What's your name, miss?" << endl;
        naming();
    }
    else if (gender == "other")
    {
        cout << "What's your name, person?" << endl;
        naming();
    }
    else if (gender != "male" || gender != "female" || gender != "other")
    {
        cout << "That doesn't answer the question, person!" << endl;
    }

    }
}

int naming()
{
    cin >> name;
    cout << "Hello, " << name << endl << "You are a " << gender << " named " << name << "? (y/n)" << endl;
    cin >> clarification;
    if (clarification == "y")
    {
        cout << "Great!";
    }

    if (clarification == "n")
    {
        cout << "Aww" << endl;
    }
    cin.get();
    return 0;
}
Where do you have anything to make it exit the loop? The return 0 on line 61 returns from the naming function, not from main ;)


else if (gender != "male" || gender != "female" || gender != "other")
1. If gender == male, it is still != female and != other
2. You already checked all three aces above, so why do you even need the if? Just leave it as an else.
Last edited on
also...

while (gender == "male" || "female" || "other")

That doesn't do what you want.
It doesn't? Sorry for not replying, I fell asleep at the keyboard.
Well, I got the program to close by putting return 0; after the 3 naming(); that were in the if statements. The program seems to work fine, but I did change else if (gender != "male" || gender != "female" || gender != "other") to else if (gender != "male" && gender != "female" && gender != "other")
Just change it to "else" and no if. ;)
In the while loop, at the end of each " if " statement, you can write " break; ".
Topic archived. No new replies allowed.