Bugfix help

Write your question here.

HI am trying to make a program that evaluates and gives a response based on the users name and gender. I cannot figure out why it is giving the responses it gives. When USERSEX and BOTSEX are the same it will sometimes say that they are different. As I am new to programming, if you locate the problem I would appreciate help in English. Thanks
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <string>
#include <ctime>

using namespace std;
int main ()
{
    int xRan;
    string BOTNAME;
    int BOTSEX;
    int USERSEX;
    string USERNAME;
    srand( time(0));
    xRan=rand()%4+1;
    if (xRan == 1)
    {
        cout << "My name is Max, what's your name?"<< endl;
        BOTNAME = "Max";
        BOTSEX ==2;
    }
    
    else if (xRan == 2)
    {
        cout << "My name is Alex, what's your name?"<< endl;
        BOTNAME = "Alex";
        srand( time(0));
        BOTSEX == rand()%2+1;
    }
    
    else if (xRan == 3)
    {
        cout << "My name is Dezi, what's your name?"<< endl;
        BOTNAME = "Dezi";
        BOTSEX == 1;
    }
    
    else
    {
        cout << "My name is Bash, what's your name?"<< endl;
        BOTNAME = "Bash";
        BOTSEX == 2;
    }
    cin >> USERNAME;
    cout << USERNAME << " is a really cool name." << endl;
    cout << "Are you MALE or FEMALE? Type 1 for female or 2 for male." << endl;
    cin >> USERSEX;
    string botsex;
    string usersex;
    if (BOTSEX == 2)
    {
        botsex = "male";
    }
    else
    {
        botsex = "female";
    }
    if (USERSEX == 2)
    {
        usersex = "male";
    }
    else
    {
        usersex = "female";
    }
    if (BOTSEX == USERSEX)
    {

        cout << "We are both " << usersex << ". isn't that cool!" << endl;
    
    }
    else
    {
        cout << "So you are " << usersex << " and I am " << botsex << ", isn't that cool!";
    }

    
return 0;
}
Hello lukecplusplus. I would like to start by saying you code is a bit of a mess atm, lol, but I did find the issue in your code non the less. In line 19, 27, 34, 41, you have BOTSEX == x. When using the double equals sign, you are not setting BOTSEX to 1 or 2, but instead actually doing a check, meaning, for example, in line 19, you are saying "Is BOTSEX equal to 2". What you want, is to have just have a single equal sign, which is how you set the variable. Here is your answer:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// line 19
// former line BOTSEX ==2;
BOTSEX = 2;

// line 27
// former line BOTSEX == rand()%2+1;
BOTSEX = rand()%2 + 1;

// line 34
// former line BOTSEX == 1;
BOTSEX = 1;

//line 41
// former line BOTSEX == 2;
BOTSEX = 2;
Thank you for the help! I fixed the lines you said and I am very grateful. I am trying to teach myself how to do all of this and your explanation was very helpful. For future reference I will leave the fixed code below. What exactly did you mean by messy code? Are there examples or webpages of messy or non messy 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <string>
#include <ctime>

using namespace std;
int main ()
{
    int xRan;
    string BOTNAME;
    int BOTSEX;
    int USERSEX;
    string USERNAME;
    srand( time(0));
    xRan=rand()%4+1;
    if (xRan == 1)
    {
        cout << "My name is Max, what's your name?"<< endl;
        BOTNAME = "Max";
        BOTSEX = 2;
    }
    
    else if (xRan == 2)
    {
        cout << "My name is Alex, what's your name?"<< endl;
        BOTNAME = "Alex";
        srand( time(0));
        BOTSEX = rand()%2+1;
    }
    
    else if (xRan == 3)
    {
        cout << "My name is Dezi, what's your name?"<< endl;
        BOTNAME = "Dezi";
        BOTSEX = 1;
    }
    
    else
    {
        cout << "My name is Bash, what's your name?"<< endl;
        BOTNAME = "Bash";
        BOTSEX = 2;
    }
    cin >> USERNAME;
    cout << USERNAME << " is a really cool name." << endl;
    cout << "Are you MALE or FEMALE? Type 1 for female or 2 for male." << endl;
    cin >> USERSEX;
    string botsex;
    string usersex;
    if (BOTSEX == 2)
    {
        botsex = "male";
    }
    else
    {
        botsex = "female";
    }
    if (USERSEX == 2)
    {
        usersex = "male";
    }
    else
    {
        usersex = "female";
    }
    if (BOTSEX == USERSEX)
    {

        cout << "We are both " << usersex << ". isn't that cool!" << endl;
    
    }
    else
    {
        cout << "So you are " << usersex << " and I am " << botsex << ", isn't that cool!";
    }

    
return 0;
}
just a concern, why are you seeding twice?
I wouldn't really consider that messy. Maybe put some spacing in between lines but that's about it honestly.
Topic archived. No new replies allowed.