Problem with bool turn in my code need help

Apr 8, 2016 at 3:28pm
so basically I was doing a program on a game called chinciro and I need help because whenever I run the program it displays a runtime error which says that my variable "turn" ( bool turn;) is being used but not initialized so here is my code:
<code>
int main()
{
for (int roundcntr = 1; roundcntr < 11; roundcntr++)
{
cout << "Welcome to our base where we play undeground chinchiro" << endl;
cout << "Round " << roundcntr << " of " << 10 << endl;
int perica = 90000;
int bet;
Roll dice = rollDice();
Roll pissr = rollDice();
// things to consider when function is in use
int value1;
int value2;
bool snakeeyes1 = true;
bool snakeeyes2 = true;
bool triple1 = true;
bool triple2 = true;
bool pisser1 = true;
bool pisser2 = true;
bool turn = true;
bool roll4561 = true;
bool roll4562 = true;
bool pairs1 = true;
bool pairs2 = true;
int valuet1;
int valuet2;
bool roll1231 = true;
bool roll1232 = true;


cout << "Perica: " << perica << endl;
cout << "Your Bet: ";
cin >> bet;

if (pissr.pisser == 5) // pisser
{
if (turn == true)
{
cout << "Kaiji Rolls..." << endl;
value1 = 1;
pisser1 = true;
turn = false;
}

else if (turn == false)
{
cout << "Ohsuki Rolls..." << endl;
value2 = 1;
pisser2 = true;
turn = true;
}
cout << "Pisser" << endl;
}

// snake eyes

else if (dice.diceA == 1 && dice.diceB == 1 && dice.diceC == 1)
{
if (turn == true)
{
cout << "Kaiji Rolls..." << endl;
value1 = 14;
snakeeyes1 = true;
turn = false;
}

else if (turn == false)
{
cout << "Ohtsuko Rolls..." << endl;
value2 = 14;
snakeeyes2 = true;
turn = true;
}

cout << "Snake Eyes" << dice.diceA << " " << dice.diceB << " " << dice.diceC << endl;
}

//triples

else if (dice.diceA == 6 && dice.diceB == 6 && dice.diceC == 6)
{
if (turn == true)
{
cout << "Kaiji Rolls..." << endl;
value1 = 13;
valuet1 = 6;
triple1 = true;
turn = false;
}

else if (turn == false)
{
cout << "Ohtsuko Rolls..." << endl;
value2 = 13;
valuet2 = 6;
triple2 = true;
turn = true;
}

cout << "Triples" << dice.diceA << " " << dice.diceB << " " << dice.diceC << endl;
}

else if (dice.diceA == 5 && dice.diceB == 5 && dice.diceC == 5)
{
if (turn == true)
{
cout << "Kaiji Rolls..." << endl;
value1 = 12;
valuet1 = 5;
triple1 = true;
turn = false;
}

else if (turn == false)
{
cout << "Ohtsuko Rolls..." << endl;
value2 = 12;
valuet2 = 5;
triple2 = true;
turn = true;
}

cout << "Triples" << dice.diceA << " " << dice.diceB << " " << dice.diceC << endl;
}
</code>

sorry for the very long code but at least help me with what am I suppose to do with the error thanks anyways.
Last edited on Apr 8, 2016 at 11:30pm
Apr 8, 2016 at 5:00pm
This clearly is not your entire code. turn is defined and initialized at line 23, so the problem must be elsewhere.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Pet peeve:
1
2
3
4
5
6
if (turn == true)
{  // some code
}
else if (turn == false)
{  // some other code/
}

There is NO reason to have if (turn == false)
If a bool is not true, then it only be false. Only the else is needed. No reason to test again.
Last edited on Apr 8, 2016 at 5:05pm
Apr 8, 2016 at 5:41pm
Peeve, and then some:
1
2
3
4
5
6
if ( turn ) // turn == true, if turn is true
{  // some code
}
else
{  // some other code
}


whenever I run the program it displays a runtime error which says that my variable "turn" ( bool turn;) is being used but not initialized

I've seen compiler warn about use of uninitialized variable, but never a program.
Apr 8, 2016 at 6:18pm
Run-Time Error Checks (/RTCu): https://msdn.microsoft.com/en-us/library/8wtf2dfz.aspx

Enabled by default in Visual Studio Debug builds.
Topic archived. No new replies allowed.