Need help with C++ programming code. I am not able to add the spin(toss) coin to
ID: 3569787 • Letter: N
Question
Need help with C++ programming code. I am not able to add the spin(toss) coin to player 2 throw the toss.
----
this is code blocks processor-
This part is not working when I add :
while (time1)
{
//a coin tossed in the air for a certain amount of time.
advance_coinspinner();
Sleep(100);
time1=time1-2000;
}
The spin only shows when player 1 toss the coin. can anyone help with player 2 ? thank you.
=============================================================================
//Each player will toss a coin .
for heads or tails.
// Then Player 1 will call out heads or tails
//- Player 2 will expose their penny and if Player 1 is correct they get one point.
// Next Player 2 will call out heads or tails -
//if they are correct they get a point. If either of the player is wrong - they lose a point.
// The game continues for 20 spins
// and then the game concludes with either a winner (Player 1 or 2)
#include
#include
#include
#include
#include
#include
using namespace std;
//global variables
void displayCoinshape();
void game();
void advance_coinspinner();
void download();
int finalCount(int win1,int win2);
string player1,player2;
string type;
int time1;
int main()
{
//COLOR#1
system("COLOR B4");//declare variables
//string player1,player2;
int player =1;
int time1=30000;
int win1=0;
int win2=0;
int count=0;
char guess;
char toss[]= {'h','t'};
char tos;
char choice = 'Y';
//COIN display shape (1)
displayCoinshape();
//game match
game();
//color #2
system("COLOR F1");
//random definition
srand(time(NULL));
do
{
time1=30000; //declare time for coin toss : advance_coinspinner function.
if(player == 1 )//start the game with player 1.
{
cout< cout<<"Player 1"<< "-"< cout< while (time1)
{
//a coin tossed in the air for a certain amount of time.
advance_coinspinner();
Sleep(100);
time1=time1-2000;
}
tos=toss[rand()%2];//generating random toss
player = 0; //declare player #1
cout<<"Player 2"<< "-"< cout< cout <<"Do you guess Heads (h) or Tails (t)? ";
cin>>guess;
cout< cout<<"Tossed coin is: "< cout< cout<<" Guessed toss is: "< count++; //count number of games played.
if(guess==tos) //condition if player has guessed correctly.
{
cout<
if(win2>win1)
{
cout<<" Final score:"<
cout< download(); //decorative shape of at the end of each game.
cout< }
}
else //switch players, now player 2 toss the coin.
{
cout<<"Player 2"<< "-"< cout<
tos=toss[rand()%2];//generating random toss
}
player = 1; //declare player #2
cout<<"Player 1"<< "-"< cout< cout <<"Do you guess Heads (h) or Tails (t) ? ";
cin>>guess;//store guess
cout< cout<<"Tossed coin is: "< cout< cout<<" Guessed toss is: "< count++;//increment game count.
if(guess ==tos)
{
cout<
if(guess !=tos)//guess was chosen incorrectly. Whoever tossed the coin wins.
{
cout<
void displayCoinshape()//start with a coin shape for decoration and welcome.
{
int val = 1;
for(int i = 0; i < 1; ++i)
{
cout << "/0"; //display this format on the screen for decoration purpose only.
for(int i = 0; i < 39; ++i)
{
cout << "/0";
}
cout << " " << endl
<< " " << endl
<< " WELCOME TO THE PENNIE GAME " < << " READY TO PLAY - A - GAME? " << endl
<< " " << endl
<< " " << endl;
int val = 25;
for(int i = 0; i < 40; ++i){
cout << "/0"; //display this format on the screen for decoration purpose only.
}
if(i % val == 0)
{
Sleep(900);//Timer speed of the rolling /0 decoration display.
// j is for the length of "" download displayed in screen.
}
cout< }
cout << " **###### #### ####***"< << " **## || ##**" < <<" **## ||||| ##**" << endl
<< " **## || ##**" << endl
<< " **## || ##**" << endl
<< " **## || ##**" << endl
<< " **## || ##**" << endl
<< " **## || ##**" << endl
<< " **## ||||||||||| ##**"<< endl
<< " **## ##**"<< endl
<<" **###### ###### ####*** " << endl << endl;
}
void game()//start this game with the following message:
{
char choice ='a'; //declare char with the first letter of alphabet.
//prompt user to enter Yes to start the game.
cout<<" Enter (Y) to play a two player game:====>"; //user entered yes
//cin>>yes;
cin >> choice;
choice = toupper(choice);//upper or lower case letters allowed.
system ("cls");
if (choice != 'Y')//choice is to quit the game.
{
cout << "Good Bye" << endl;
exit(0);
}
//prompt user to enter an alias
cout<<"Player 1 - What is your alias? ";
//user entered an alias
cin>>player1;
cout< //prompt second user to enter an alias
cout<<"Player 2 - What is your alias? ";
//user entered his/her alias
cin>>player2;
cout< system ("cls");
//prompt user to enter yes to start or no to quit the game
cout < cin >> choice;
cout< choice = toupper(choice); //make choice upper case all the time.
if (choice != 'Y')
{
cout << "Good Bye" << endl;
exit(0);
}
}
void download()
{
//download will start value increment in 25 x50x75x100x125
int val = 25;
for(int i = 0; i < 125; ++i){
cout << "/0"; //display this format on the screen for decoration purpose only.
if(i % val == 0)
{
Sleep(300);//Timer speed of the decoration display.
// j is for the length of "" download displayed in screen.
for(int j = 0; j < 38; ++j)
{
cout << "";
}
}
//at the end of 93, display the following message:
if(i == 93)
{
char choice = 'Y';
cout<<" LET ME KNOW IF YOU WISH TO QUIT THIS GAME NOW."< << "Enter (X) to EXIT or (Y) to CONTINUE.";
cin>>choice;
for(int i = 0; i < 92; ++i){
cout << "/0";
if(i % val == 0)
{
cout< system ("cls");
cout< choice = toupper(choice);
}
}
if (choice != 'Y')
{
cout << " Good Bye!!" << endl;
exit(0);
}
}
}
return;
}
//display the coin tossed in the air.
void advance_coinspinner()
{
static char coin[] = { 'O', '-', 'O', '|' };
static int nbars = sizeof(coin) / sizeof(char);
static int pos = 0;
printf(" %c ",coin[pos]);
fflush(stdout);
pos = (pos + 1) % nbars;
return;
}