main method Prompt for players name and store it in a varia
/* main method Prompt for player\'s name and store it in a variable Declare a variable to contain the score and initialize it to zero Create a loop which does the following: Prompt user whether or not to spin If N, exit the loop if Y, call the spin method (which returns the spin result) if -1, display \"hit Whammy\" and exit the loop if > 0, update score and display the result */ /* spin method - Create an array containing the following values: 1000,1500,750,600,500,100,250,750,600,1500,-1,500,1000,1500,750,-1,500,1500 - Generate a random number which represents the index location of one of the 18 numbers in the array - Return that number from the array to the main method */
/*Revision of Whammy1 with the following changes: - If it’s not already there, move the Scanner declaration outside the main method so it can be used in other methods. You\'ll need to declare it as static so it can be used in multiple methods - Update game to two players (with separate variables for each player’s name and score) - Update the Continuous loop in the main method with each player alternates taking a turn until they choose to stop spinning or hit a Whammy - The first player to hit 10,000 is the winner. Announce the winner and end the game when the first player hits 10,000. If the first player hits 10,000, allow the second player one more turn. If both players exceed 10,000, the winner is the player with the highest score. Note that a tie is unlikely, but possible, so include that condition. - Create a new method called takeTurn which contains all the logic of one player completing a turn. - Pass the player\'s current score from the main method as a parameter in the takeTurn method it can update the score. - You will call the spin method from within the takeTurn method. At the end of takeTurn, when the player’s turn ends, return the player\'s updated score back to the main method.
Solution
#include<stdlib.h>
#include<iostream.h>
static int score1, score2, score, res;
score1=0;
score2=0;
char name1[25],name2[25], ch[2];
void main()
{
cout<<\"Enter 1st player\'s name: \";
cin>>name1;
cout<<\"Enter 2nd player\'s name: \";
cin>>name2;
while(score1<10000 || score2<10000)
{
takeTurn(name1);
{
score1=score;
}
takeTurn(name2);
{
score2=score;
}
}
if (score1>10000 && score2<10000)
{
cout<< \"Winner is player1\";
takeTurn(name2);
}
else if (score1>10000 && score2>10000)
{
if(score1>score2)
cout<<\"Player 1 is winner \";
else
cout<<\"Player 2 is winner\";
}
else if (score1 = = score2)
{
takeTurn(name1);
takeTurn(name2);
}
}
int takeTurn(name)
{
cout<<name<<\"Do you want to spin (Y/N): \";
cin>>ch;
if(ch==N)
exit;
else
{
res=spin();
if(res = = -1)
cout<<\"Hit Whammy\";
else
exit;
if (res >0)
{
score = score + res;
return score;
}
int spin()
{
int a[] = { 1000, 1500, 750, 600, 500, 100, 250, 750, 600, 1500, -1500, 1000, 1500, 750, -1500, 1500};
int *p;
return rand(p);
}



