// Declare Variables
int pigDice = 0;
int gamerDice = 0;
int gamerTurn = 0;
int computerTurn = 0;
int gamerInput = 0;
int totalScore;
const int SCORE_LIMIT = 100;
char choice = ' ';
int gamerScore = 0;
int turnScore = 0;
int pigScore = 0;
int main()
{
cout << "Welcome to ARCADEMANIA" << endl;
cout << "Enter 1 to play Pig " << endl;
cout << "Enter 2 to play Blackjack dice" << endl;
cin >> gamerInput;
char gamerName[12];
cout << "WELCOME TO PIG GAME" << endl;
cout << "Hi welcome to Pig you will be trying to beat Wilbert to 100 pts. Rember you cannot roll a 1 or you will lose a turn and will not get any points. Wilbert is excited to play goodluck and roll on" << endl;
cout << "Please enter your gamer name" << endl;
cin >> gamerName;
cout << " Welcome to Pig " << gamerName << " Lets see that you got!!!!!" << endl;
cout << "Press r to roll.\n" << endl;
cin >> choice;
do
{
cout << "Your roll is a " << gamerDice << endl;
cout << "Your total score is " << gamerScore << endl;
cin >> choice;
gamerDice = (rand() % 6) + 1;
gamerScore = gamerScore + gamerDice;
}
while (choice == 'r');
{
cout << "Will you like to roll" << endl;
cout << "Press r to roll.\n" << endl;
cin >> choice;
cout << "Your roll is a " << gamerDice << endl;
cout << "Your total score is " << gamerScore << endl;
cout << "Will you like to roll again" << endl;
gamerDice = (rand() % 6) + 1;
gamerScore = gamerScore + gamerDice;
}
if (gamerDice == 1)
cout << gamerName << "You lose your points for this round your " << totalScore << endl;
do
{
pigDice = (rand() % 6) + 1;
pigScore = pigScore + pigDice;
cout << "Your roll is a " << pigDice << endl;
cout << "Your total score is " << pigScore << endl;
}
while (pigDice != 1 && totalScore < 20);
if (pigDice == 1)
cout << "You lose your turn Pig!!! " << gamerName << " press 'r' to roll die. \n" << endl;
You have some scoping issues and it's no surprise since you've yet to develop a white spacing style preference. Let's clean up your white space, add some comments and use the code blocks. Then see if you can see the problem:
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<ctime>
usingnamespace std;
// Declare Variables
int pigDice = 0;
int gamerDice = 0;
int gamerTurn = 0;
int computerTurn = 0;
int gamerInput = 0;
int totalScore;
constint SCORE_LIMIT = 100;
char choice = ' ';
int gamerScore = 0;
int turnScore = 0;
int pigScore = 0;
int main()
{
cout << "Welcome to ARCADEMANIA" << endl;
cout << "Enter 1 to play Pig " << endl;
cout << "Enter 2 to play Blackjack dice" << endl;
cin >> gamerInput;
srand(static_cast<int>(time(0)));
pigDice = (rand() % 6) + 1;
gamerDice = (rand() % 6) + 1;
gamerScore = gamerScore + gamerDice;
while(gamerInput == 1)
{
char gamerName[12];
cout << "WELCOME TO PIG GAME" << endl;
cout << "Hi welcome to Pig you will be trying to beat Wilbert to 100 pts. Rember you cannot roll a 1 or you will lose a turn and will not get any points. Wilbert is excited to play goodluck and roll on" << endl;
cout << "Please enter your gamer name" << endl;
cin >> gamerName;
cout << " Welcome to Pig " << gamerName << " Lets see that you got!!!!!" << endl;
cout << "Press r to roll.\n" << endl;
cin >> choice;
do
{
cout << "Your roll is a " << gamerDice << endl;
cout << "Your total score is " << gamerScore << endl;
cin >> choice;
gamerDice = (rand() % 6) + 1;
gamerScore = gamerScore + gamerDice;
}while (choice == 'r'); //END OF DO FROM LINE 46
{//THIS IS WHAT IS CALLED AN ANONYMOUS SCOPE. IT DOES NOTHING FOR YOU IN THIS CONTEXT
cout << "Will you like to roll" << endl;
cout << "Press r to roll.\n" << endl;
cin >> choice;
cout << "Your roll is a " << gamerDice << endl;
cout << "Your total score is " << gamerScore << endl;
cout << "Will you like to roll again" << endl;
gamerDice = (rand() % 6) + 1;
gamerScore = gamerScore + gamerDice;
}//END OF USELESS ANONYMOUS SCOPE
if (gamerDice == 1) cout << gamerName << "You lose your points for this round your " << totalScore << endl;
do
{
pigDice = (rand() % 6) + 1;
pigScore = pigScore + pigDice;
cout << "Your roll is a " << pigDice << endl;
cout << "Your total score is " << pigScore << endl;
}while (pigDice != 1 && totalScore < 20); //END OF DO FROM LINE 69
if (pigDice == 1) cout << "You lose your turn Pig!!! " << gamerName << " press 'r' to roll die. \n" << endl;
system("pause");
return 0;
}//END OF WHILE FROM LINE 34
}//END OF MAIN
// Declare Variables
int pigDice = 0;
int gamerDice = 0;
int gamerTurn = 0;
int computerTurn = 0;
int gamerInput = 0;
int totalScore;
const int SCORE_LIMIT = 100;
char choice = ' ';
int gamerScore = 0;
int turnScore = 0;
int pigScore = 0;
int main()
{
cout << "Welcome to ARCADEMANIA" << endl;
cout << "Enter 1 to play Pig " << endl;
cout << "Enter 2 to play Blackjack dice" << endl;
cin >> gamerInput;
while (gamerInput == 1)
{
char gamerName[12];
cout << "WELCOME TO PIG GAME" << endl;
cout << "Hi welcome to Pig you will be trying to beat Wilbert to 100 pts. Rember you cannot roll a 1 or you will lose a turn and will not get any points. Wilbert is excited to play goodluck and roll on" << endl;
cout << "Please enter your gamer name" << endl;
cin >> gamerName;
cout << " Welcome to Pig " << gamerName << " Lets see that you got!!!!!" << endl;
cout << "Press r to roll.\n" << endl;
cin >> choice;
do
{
cout << "Your roll is a " << gamerDice << endl;
cout << "Your total score is " << gamerScore << endl;
cin >> choice;
gamerDice = (rand() % 6) + 1;
gamerScore = gamerScore + gamerDice;
} while (choice == 'r');
if (gamerDice == 1) cout << gamerName << "You lose your points for this round your " << totalScore << endl;
do
{
pigDice = (rand() % 6) + 1;
pigScore = pigScore + pigDice;
cout << "Your roll is a " << pigDice << endl;
cout << "Your total score is " << pigScore << endl;
} while (pigDice != 1 && totalScore < 20);
if (pigDice == 1) cout << "You lose your turn Pig!!! " << gamerName << " press 'r' to roll die. \n" << endl;