if Statement not recognised.

Within my int main () has an if statement that suppose to add 1, 2 or 3 to a variable named anicrds and then add that to a either player one or player two total animal cards depending on whether it player one or two turn but when ever the conditions are true (player one or player two are on the spot 7, 14, etc) The program doesn't recognise the if statement. It's getting very frustrating please help.
N.B. This program I had to do in 3 steps. This is the 3rd one. Everything isn't fine tuned so bare with it. I tested alot with it and something might not be right.

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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

//This function will tell the user to roll the dice.
void rollPrompt(int press) {
if (press == 1) {
    cout << "Please press enter to roll the dice." << endl;
    cin.ignore();
    } else {
    cout << "Please press enter to roll the dice again." << endl;
    }
    cin.ignore();
}

//This Function is the Random number genrate and declares whether the player has landed on binocuars or not.
int diceRoll(){
int ran;
cout << "" <<endl;
for (int x = 0; x < 2; x++) {
    srand(time(0));
    ran = rand()%6+1;
    if (ran == 1) {
        cout << "You rolled the binoculars." << endl;
    } else {
    cout << ran;
    }
    return ran;
    }
}


int main() {
//Declaring all variables used in this scoop.
    string pOne, pTwo, startFirst, startSecond;
    int pOneAge, pTwoAge, fDie, sDie, total;
//Setting player start point to 1.
    int playerOne = 1;
    int playerTwo = 1;
    int playerTurn = 0;
    int anicrds = 0;
    int POanicrds = 0;
    int PTanicrds = 0;
    int anicrdsT = 0;
cout << "Please enter your name." <<endl;
cin >> pOne;
cout << "Please enter your age " << pOne << endl;
cin >> pOneAge;
            cout << "" <<endl;
            cout << "" <<endl;

cout << "Please enter your name." << endl;
cin >> pTwo;
cout << "Please enter your age " << pTwo << endl;
cin >> pTwoAge;
            system("CLS");
            cout << "" <<endl;
            cout << "" <<endl;

//Determining who is player one and by default player 2.
if (pOneAge <= pTwoAge){
    startFirst = pOne;
    startSecond = pTwo;
    cout << pOne << " is to play first!" << endl;
}else{
    startFirst = pTwo;
    startSecond = pOne;
    cout << pTwo << " is to play first!" << endl;
}
            cout << "" <<endl;
            cout << "" <<endl;

//Main loop function.
do {
    //Used to loop between players.
    if (playerTurn == 0) {
    cout << startFirst << endl;
    cout << "" <<endl;
    //Prompting user to roll dice.
    rollPrompt(1);
    //Generating first dice roll.
    fDie = diceRoll();
    cout << "" <<endl;
    //Prompting user to roll dice again.
    rollPrompt(2);
    //Generating second dice roll.
    sDie = diceRoll();
    cout << "" <<endl;
    cout << "" <<endl;
    //Calculating total of the 2 dice rolls.
    total = fDie + sDie;
    cout << "" <<endl;
    system("pause");
    system("CLS");

    //Displaying total of the 2 dice rolls.
    cout << startFirst << endl;
    cout << "Your total dice roll is " << total << endl;
    //Adding dice rolls to player one score to keep track of his/her position on the board.
    playerOne+=total;
    cout << "" <<endl;
    if (playerOne == 7 || playerOne == 14 || playerOne == 21 || playerOne == 28 || playerOne == 35 || playerOne == 42 || playerOne == 49 || playerOne == 56) {
        srand(time(0));
        anicrdsT = rand()%3+1;
        POanicrds += anicrdsT;
        cout << "You landed on a Binoculars." << POanicrds << endl;
        }
    //Displayer total position of player on the board.
    cout << startFirst << " is currently on " << playerOne << endl;
    cout << "" <<endl;
    //Displaying how far they are from the base camp or the end of the game.
    cout << "You are " << 65 - playerOne << " away from the base camp!" <<endl;
    cout << "" <<endl;
    system("pause");
    system("CLS");
    }
    //Starting player 2 turn.
    cout << startSecond << endl;
    cout << "" <<endl;
    //Prompting user to roll dice.
    rollPrompt(1);
    //Generating first dice roll.
    fDie = diceRoll();
    cout << "" <<endl;
    cout << "" <<endl;
    //Prompting user to roll dice again.
    rollPrompt(2);
    //Generating second dice roll.
    sDie = diceRoll();
    cout << "" <<endl;
    cout << "" <<endl;
    //Calculating total of the 2 dice rolls.
    total = fDie + sDie;
    cout << "" <<endl;
    system("pause");
    system("CLS");
    //Displaying total of the 2 dice rolls.
    cout << startSecond << endl;
    cout << "Your total dice roll is " << total << endl;
    //Adding dice rolls to player two score to keep track of his/her position on the board.
    playerTwo+=total;
    cout << "" <<endl;
    if (playerTwo == 7 || playerTwo == 14 || playerTwo == 21 || playerTwo == 28 || playerTwo == 35 || playerTwo == 42 || playerTwo == 49 || playerTwo == 56) {
        srand(time(0));
        anicrdsT = rand()%3+1;
        PTanicrds += anicrdsT;
        cout << "You landed on a Binoculars." << PTanicrds << endl;
        }
    //Displayer total position of player on the board.
    cout << startSecond << " is currently on " << playerTwo << endl;
    cout << "" <<endl;
    //Displaying how far the player is from the base camp or the end of the game.
    cout << "You are " << 65 - playerTwo << " away from the base camp!" <<endl;
    cout << "" <<endl;
    cout << "" <<endl;
    system("pause");
    system("CLS");
    //Conditions for the loop.
    } while (playerOne <= 65 || playerTwo <= 65);
    //Condition to determine the winner of the game.
    if (playerOne >= 65) {
        cout << "The winner is " << startFirst << endl;
    } else if (playerTwo >= 65) {
        cout << "The winner is " << startSecond << endl;
    };
return 0;
}
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

//This function will tell the user to roll the dice.
void rollPrompt(int press) {
if (press == 1) {
    cout << "Please press enter to roll the dice." << endl;
    //cin.ignore();     Don't need this
    } else {
    cout << "Please press enter to roll the dice again." << endl;
    }

    cin.get(); // Added this
}

//This Function is the Random number genrate and declares whether the player has landed on binocuars or not.
int diceRoll(){
int ran;
//cout << "" <<endl;

    ran = rand()%6+1;
   // if (ran == 1) {
   //     cout << "You rolled the binoculars." << endl;
  //  } else {
    cout << ran << endl; // Output the number and then return it
   // }
    return ran;

}


int main() {
    srand(time(0)); // Do this only once here
//Declaring all variables used in this scoop.
    string pOne, pTwo, startFirst, startSecond;
    int pOneAge, pTwoAge, fDie, sDie, total;
//Setting player start point to 1.
    int playerOne = 1;
    int playerTwo = 1;
    int playerTurn = 0;
   // int anicrds = 0; This is unused
    int POanicrds = 0;
    int PTanicrds = 0;
    int anicrdsT = 0;
cout << "Please enter your name." <<endl;
cin >> pOne;
cout << "Please enter your age " << pOne << endl;
cin >> pOneAge;
       //     cout << "" <<endl;
        //    cout << "" <<endl;

cout << "Please enter your name." << endl;
cin >> pTwo;
cout << "Please enter your age " << pTwo << endl;
cin >> pTwoAge;
          //  system("CLS");
           // cout << "" <<endl;
           // cout << "" <<endl;

//Determining who is player one and by default player 2.
if (pOneAge <= pTwoAge){
    startFirst = pOne;
    startSecond = pTwo;
    cout << pOne << " is to play first!" << endl;
}else{
    startFirst = pTwo;
    startSecond = pOne;
    cout << pTwo << " is to play first!" << endl;
}
        //    cout << "" <<endl;
          //  cout << "" <<endl;

//Main loop function.
do {
    //Used to loop between players.
    if (playerTurn == 0) {
    cout << startFirst << endl;
   // cout << "" <<endl;
    //Prompting user to roll dice.
    rollPrompt(1);
    //Generating first dice roll.
    fDie = diceRoll();
   // cout << "" <<endl;
    //Prompting user to roll dice again.
    rollPrompt(2);
    //Generating second dice roll.
    sDie = diceRoll();
   // cout << "" <<endl;
   // cout << "" <<endl;
    //Calculating total of the 2 dice rolls.
    total = fDie + sDie;
  //  cout << "" <<endl;
   // system("pause");
   // system("CLS");

    //Displaying total of the 2 dice rolls.
    cout << startFirst << endl;
    cout << "Your total dice roll is " << total << endl;
    //Adding dice rolls to player one score to keep track of his/her position on the board.
    playerOne+=total;
   // cout << "" <<endl;
    if (playerOne == 7 || playerOne == 14 || playerOne == 21 || playerOne == 28 || playerOne == 35 || playerOne == 42 || playerOne == 49 || playerOne == 56) {
        cout << "You got in if" << endl; // Added this, so you can notice when you get in if, remove it later
        anicrdsT = rand()%3+1;
        POanicrds += anicrdsT;
        cout << "You landed on a Binoculars." << POanicrds << endl;
        }
    //Displayer total position of player on the board.
    cout << startFirst << " is currently on " << playerOne << endl;
 //   cout << "" <<endl;
    //Displaying how far they are from the base camp or the end of the game.
    cout << "You are " << 65 - playerOne << " away from the base camp!" <<endl;
   // cout << "" <<endl;
   // system("pause");
   // system("CLS");
    }
    //Starting player 2 turn.
    cout << startSecond << endl;
  //  cout << "" <<endl;
    //Prompting user to roll dice.
    rollPrompt(1);
    //Generating first dice roll.
    fDie = diceRoll();
  //  cout << "" <<endl;
  //  cout << "" <<endl;
    //Prompting user to roll dice again.
    rollPrompt(2);
    //Generating second dice roll.
    sDie = diceRoll();
   // cout << "" <<endl;
  //  cout << "" <<endl;
    //Calculating total of the 2 dice rolls.
    total = fDie + sDie;
 //   cout << "" <<endl;
 //   system("pause");
  //  system("CLS");
    //Displaying total of the 2 dice rolls.
    cout << startSecond << endl;
    cout << "Your total dice roll is " << total << endl;
    //Adding dice rolls to player two score to keep track of his/her position on the board.
    playerTwo+=total;
 //   cout << "" <<endl;
    if (playerTwo == 7 || playerTwo == 14 || playerTwo == 21 || playerTwo == 28 || playerTwo == 35 || playerTwo == 42 || playerTwo == 49 || playerTwo == 56) {
        cout << "You got in if" << endl; // Added this, so you can notice when you get in if, remove it later
        anicrdsT = rand()%3+1;
        PTanicrds += anicrdsT;
        cout << "You landed on a Binoculars." << PTanicrds << endl;
        }
    //Displayer total position of player on the board.
    cout << startSecond << " is currently on " << playerTwo << endl;
   // cout << "" <<endl;
    //Displaying how far the player is from the base camp or the end of the game.
    cout << "You are " << 65 - playerTwo << " away from the base camp!" <<endl;
   // cout << "" <<endl;
   // cout << "" <<endl;
   // system("pause");
  //  system("CLS");
    //Conditions for the loop.
    } while (playerOne <= 65 || playerTwo <= 65);
    //Condition to determine the winner of the game.
    if (playerOne >= 65) {
        cout << "The winner is " << startFirst << endl;
    } else if (playerTwo >= 65) {
        cout << "The winner is " << startSecond << endl;
    };
return 0;
}


Well, I mostly commented things out.
Added couple things and changed some things, I added comments about what I changed roughly.
add a breakpoint on the line where your 'dodgy' if statement is. when you hit it examine the contents of your playerTwo/playerOne variables just to make 100% sure that the if condition should evaluate to true.

(or print out the values of playerOne and playerTwo just before the if statements)
Last edited on
Topic archived. No new replies allowed.