Loop Problems

I am having difficulties, when I input "I" or "F" (into turnover() ) it doesn't run the "interception()" or "fumble ()" function. In addition when I input "T" it simply restates the prompt. I can't figure out why this is happening. *Note: Safety works fine

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
void changeteam (){
    teamswap = teamswap + 1;
    if (teamswap = 2){
        teamswap = 0;
    }
}

void interception (){
    int playernumber1;
    int playernumber2;
    cout << "Who threw the interception? (Player #)" << endl;
    cin >> playernumber1;
    cout << "Who caught the interception? (Player #)" << endl;
    cin >> playernumber2;
    int currentyards;
    char currentresponse;
    cout << "How long was the return?" << endl;
    cin >> currentyards;
    while (currentresponse != 'Y' && currentresponse != 'N'){
            cout << "Was it returned for a touchdown? (Y or N)" << endl;
            cin >>  currentresponse;
    }
    if (teamswap = 1){
        away.interception();
        awayp.intthrow(playernumber1);
        homep.intmade(playernumber2);
        home.defreturn(currentyards);
        homep.defyards(currentyards,playernumber2);
        if (currentresponse == 'Y'){
            home.returnfortd();
            homep.deftds(playernumber2);
            extrapoint();
        }
        changeteam();
    }
    else if (teamswap = 0){
        home.interception();
        homep.intthrow(playernumber1);
        awayp.intmade(playernumber2);
        away.defreturn(currentyards);
        awayp.defyards(currentyards,playernumber2);
        if (currentresponse == 'Y'){
            away.returnfortd();
            awayp.deftds(playernumber2);
            extrapoint();
        }
        changeteam();
    }
}

void fumble (){
    int playernumber1;
    int playernumber2;
    int currentyards;
    char currentresponse;
    cout << "Who fumbled? (Player #)" << endl;
    cin >> playernumber1;
    cout << "Who recovered? (PLayer #)" << endl;
    cin >> playernumber2;
    if (teamswap = 1){
        away.fumble();
        awayp.fumgiv(playernumber1);
        cout << "How long was the return?" << endl;
        cin >> currentyards;
        home.defreturn(currentyards);
        homep.defyards(currentyards,playernumber2);
        while (currentresponse != 'Y' && currentresponse != 'N'){
            cout << "Was it returned for a touchdown? (Y or N)" << endl;
            cin >>  currentresponse;
            if (currentresponse == 'Y'){
                home.returnfortd();
                homep.deftds(playernumber2);
                extrapoint();
            }
        }
        homep.fumrec(playernumber2);
        changeteam();
    }
    else if (teamswap = 0){
        home.fumble();
        homep.fumgiv(playernumber1);
        cout << "How long was the return?" << endl;
        cin >> currentyards;
        away.defreturn(currentyards);
        awayp.defyards(currentyards,playernumber2);
        while (currentresponse != 'Y' && currentresponse != 'N'){
            cout << "Was it returned for a touchdown? (Y or N)" << endl;
            cin >>  currentresponse;
            if (currentresponse == 'Y'){
                away.returnfortd();
                awayp.deftds(playernumber2);
                extrapoint();
            }
        }
        homep.fumrec(playernumber2);
        changeteam();
    }
}

void safety (){
    int playernumber;
    cout << "Who got the safety? (Player #)" << endl;
    cin >> playernumber;
    if (teamswap = 1){
        away.safety();
        homep.safe(playernumber);
        punt();
        changeteam();
    }
    else if (teamswap = 0){
        home.safety();
        awayp.safe(playernumber);
        punt();
        changeteam();
    }
}

void turnover (){
    char currentresponse9;
    cout << "What kind of turnover is it?" << endl << "T - Turnover on Downs" << endl << "I - Interception" << endl << "F - Fumble" << endl << "S - Safety" << endl;
    cin >> currentresponse9;
    while (currentresponse9 != 'T' && currentresponse9 != 'I' && currentresponse9 != 'F' && currentresponse9 != 'S'){
        if (currentresponse9 == 'T'){
            changeteam();
        }
        else if (currentresponse9 == 'F'){
            fumble ();
        }
        else if (currentresponse9 == 'I'){
            interception ();
        }
        else if (currentresponse9 == 'S'){
            safety();
        }
    }
}
Last edited on
Line 23/79/104/110: I.e. if (teamswap = 1){ needs to be if (teamswap == 1){.

= -> assign value
== -> compare value

to avoid this problem you may write the constant value left. I.e. if (1 == teamswap){. The compiler will complain when you write = instead of ==.

Line 122: You get into the loop only when currentresponse9 is not one of the characters you are checking for.
Topic archived. No new replies allowed.