My probelm is im having problems in passing the game to the Computer when the user's turn is complete. How can i do this back em forth issue. So far, i have these two loops i want create functions instead. Any tip, hint is much appreciated.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
//initializes time
srand(time (NULL) );
int humanScore = 0;
int compScore = 0;
char option;
int dice;
int count = 0;
//compDie = randomNumber2;
cout << "Welcome to Pig!" << endl;
cout << "Now is your turn.";
bool play = true;
while (play)
{
cout << "Do you want roll or hold (r/h)?:";
cin >> option;
cin.get();
if ( option == 'r')
{
dice = rand() % 6 + 1;
}
else if(option == 'h')
{
play = false;
cout << " Your Score is " << humanScore << endl;
}
else
{
cout << "you pressed a wrong key, press r or h" << endl;
}
while ( humanScore >=100 || count < 5)
{
if ( dice == 1 )
{
cout << "The dice rolled is 1 and your current score is 0 . Your Score is" << humanScore << endl;
cout << "Now it's Computer's turn" << endl;
//count = 5;
} humanScore += dice;
cout << " The Dice rolled is " << dice << " and your current turn score is " << humanScore << endl;
count++;
}
while(compScore >=100)
{
if(dice == 1 )
{
cout << "The dice rolled is 1 and your current score is 0 ";
cout << "It's the human's turn";
}
} compScore += dice;
}
system ("pause");
return 0;
}

New Topic/Question
Reply




MultiQuote




|