Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ program . I am having problems with my code and require help for this program that I have writen. 1st: I would like to

C++ program . I am having problems with my code and require help for this program that I have writen. 1st: I would like to promt user either 1 or 2 players for this game. If player choose 2 player, the game would be able to tell who is the winner at the end of the game. 2nd: The looping problem for case 1, If user input wrong value, how to repromt user to input correct value. // I understand that from option 2 to 13 I am missing some code, but I got that sorted out and will add it in later after this program is solve.

#include

#include

#include

#include

using namespace std;

int ace (int dices[]);

// at the start of the program I would like to promt the user, either 1 or 2 player. At the end of the game, this program would be able to tell who is the winner between the 2 if user press 2 player. if user choose 1 player then player 1 would win the game.

int main ()

{

int check=1;

while(check==1){

int count = 0;

const int MAX_ROUNDS = 13;

const int scores = 13;

int results[scores] = {0,0,0,0,0,0,0,0,0,0,0,0,0};

int rounds = 0;

int die[5];

string keepers;

bool catUsed[13];

catUsed[1] = false;

catUsed[2] = false;

catUsed[3] = false;

catUsed[4] = false;

catUsed[5] = false;

catUsed[6] = false;

catUsed[7] = false;

catUsed[8] = false;

catUsed[9] = false;

catUsed[10] = false;

catUsed[11] = false;

catUsed[12] = false;

catUsed[13] = false;

int upperScore;

int lowerScore;

int upperBonus = 0;

while(rounds < MAX_ROUNDS)

{

rounds +=1;

srand(time(0));

cout << "This will be your first roll" << endl;

for(int i = 0; i < 5; i++)

{

die[i] = rand()%6+1;

}

cout << die[0] << ' ' << die[1] << ' ' << die[2] << ' ' << die[3] << ' ' << die[4] << endl;

cout << "1 for no-reroll or 0 for re-roll,Example: 01011 then press enter" << endl;

while(true)

{

cin >> keepers;

bool go = false;

for(int i = 0; i < keepers.size(); i++)

if(keepers[i] < '0' || keepers[i] > '1')

go = true;

break;

}

cout << "This will be your second roll" << endl;

for(int i = 0; i < 5; i++)

if(keepers[i] != '1')

die[i] = rand()%6+1;

cout << die[0] << ' ' << die[1] << ' ' << die[2] << ' ' << die[3] << ' ' << die[4] << endl;

cout << "This will be your final roll" << endl;

while(true)

{

cin >> keepers;

bool go = false;

for(int i = 0; i < keepers.size(); i++)

if(keepers[i] < '0' || keepers[i] > '1')

go = true;

break;

}

cout << "Your final rolls are: " << endl;

for(int i = 0; i < 5; i++)

if(keepers[i] != '1')

die[i] = rand()%6+1;

cout << die[0] << ' ' << die[1] << ' ' << die[2] << ' ' << die[3] << ' ' << die[4] << endl;

cout << "Please enter number from 1-13 for category to input data. " << endl;

cout << "1 - Score Aces: " << results[0] << " ";

cout << "2 - Score Twos: " << results[1] << " ";

cout << "3 - Score Threes: " << results[2] << " ";

cout << "4 - Score Fours: " << results[3] << " ";

cout << "5 - Score Fives: " << results[4] << " ";

cout << "6 - Score Sixes: " << results[5] << " ";

cout << "7 - Score 3 of a Kind: " << results[6] << " ";

cout << "8 - Score 4 of a Kind: " << results[7] << " ";

cout << "9 - Score Full House: " << results[8] << " ";

cout << "10 - Score Small Straight: " << results[9] << " ";

cout << "11 - Score Large Straight: " << results[10] << " ";

cout << "12 - Score All straight: " << results[11] << " ";

cout << "13 - Score Chance: " << results[12] << " ";

int option;

cout << "Option - ";

cin >> option;

if(option >0 && option<13){

if (catUsed[option] == true)

cout << "pick another category" << endl; // how to continue to promt user to input correct value

else

cout << "Enter Ace Score. ";

catUsed[option] = true;

results[option-1] = ace(die);

}

else{

cout << "Illegal choice made. Please choose another." << endl;

}

}

upperScore = results[0] + results[1] + results[2] + results[3] + results[4] + results[5];

lowerScore = results[6] + results[7] + results[8] + results[9] + results[10] + results[11] + results[12];

if (upperScore >= 63)

upperBonus = 35;

cout << "You have finished the game. Let's see how you did. ";

int totalScore = upperScore + upperBonus + lowerScore;

cout << "Congratulations. Your total score is " << totalScore << ". Not too shabby.";

cout << "wanna play again . Enter 1 for yes and 0 for no :";

cin >> check;

}

system("pause");

return 0;

}

int ace(int die[])

{

int count=0;

int results=0;

for (int m=0; m<5; m++)

if (die[m]==1);

{

count=count+1;

}

results=count;

return results;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions

Question

3. What strategies might you use?

Answered: 1 week ago

Question

3. Is there opportunity to improve current circumstances? How so?

Answered: 1 week ago