Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It is time for you to submit your finished Yahtzee game. Remember that your fina

ID: 667294 • Letter: I

Question

It is time for you to submit your finished Yahtzee game. Remember that your final game must be fully functional and able to be played by at least one user. Your Yahtzee game should also include the following:

Applies strings, loops, expressions, functions and variables where necessary.

C++ code that programs a random number generator for the dice.

Accurate calculations of points scored by each of the players.

Keeps the high score of the players for each game, and ranks them in order.

I have to make a Yahtzee program for class. what i have so far is down below. it is basically finished except that i cant get the ones through sixes to display correct points. in yahtzee if you want to score points in the ones spot you add up all the ones on your dice. i cant figure out a way to add only the ones on the dice and not all the dice. this is the same with twos threes fours fives and sixes.

#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main () {
//Decalre all variables
int rand ( void );
int category;
int finalscore = 0;
int round;
int dice[5];
int turn;
int threeofakind=0;
int fourofakind=0;
int fullHouse=0;
int smallStraight=0;
int largeStraight=0;
int yahtzee=0;
int chance=0;
int scratch=0;
int totalones=0, totaltwos=0, totalthrees=0, totalfours=0, totalfives=0, totalsixs=0;
char reroll[5];
srand((unsigned int) time(0));

//Randomize each dice
dice[0]=rand() % 6+1;
dice[1]=rand() % 6+1;
dice[2]=rand() % 6+1;
dice[3]=rand() % 6+1;
dice[4]=rand() % 6+1;
round=1;

//Begin Yahtzee
cout << "Welcome to Yahtzee. " ;
while (round<=13) {


for (turn=1;turn<=3; turn++) {

cout << "Round" <<" " << round << " " << "Roll#" << " " << turn << " ";
cout << "Your roll is: " << dice[0] << dice[1] << dice[2] << dice[3] << dice[4] << " (Type 'y' to re-roll or 'n' to stay)";

cin >> reroll[0] >> reroll[1] >> reroll[2] >> reroll[3] >> reroll[4];

//User decides which dice to keep and which to reroll
if (reroll[0]=='y'){
dice[0]=rand() % 6+1;}
if(reroll[0]=='n'){
dice[0];}
if (reroll[1]=='y'){
dice[1]=rand() % 6+1;}
if (reroll[2]=='y'){
dice[2]=rand() % 6+1;}
if (reroll[3]=='y'){
dice[3]=rand() % 6+1;}
if (reroll[4]=='y'){
dice[4]=rand() % 6+1;}

}

//User picks category for scoring
cout << "Under what category would you like to record your score: ";
cout << "1 - Ones: " << " ";
cout << "2 - Twos: " << " ";
cout << "3 - Threes: " << " ";
cout << "4 - Fours: " << " ";
cout << "5 - Fives: " << " ";
cout << "6 - Sixes: " << " ";
cout << "7 - 3 of a Kind: " << " ";
cout << "8 - 4 of a Kind: " << " ";
cout << "9 - Full House: " << " ";
cout << "10 -Small Straight: " << " ";
cout << "11 -Large Straight: " << " ";
cout << "12 -Yahtzee: " << " ";
cout << "13 -Chance: " << " ";
cout << "14 - Scratch: " << " ";
cout << " ";


cout << "Choice (1-14): ";
cin >> category ;
cout << " ";

//////here is my trouble
//Determine addition of ones
if (category == 1) {
if (dice[0]==1 || dice[1]==1 || dice[2]==1 || dice[3]==1 || dice[4]==1){
totalones+= dice[0] + dice[1] + dice[2] + dice[3] + dice[4];
}
}
//Determine addition of twos
else if (category ==2) {
if (dice[0]==2 || dice[1]==2 || dice[2]==2 || dice[3]==2 || dice[4]==2){
totaltwos+= dice[0] + dice[1] + dice[2] + dice[3] + dice[4];
}
}
//Determine addition of threes
else if (category ==3) {
if (dice[0]==3 || dice[1]==3 || dice[2]==3 || dice[3]==3 || dice[4]==3){
totalthrees+= dice[0] + dice[1] + dice[2] + dice[3] + dice[4];
}
}
//Determine addition of fours
else if (category ==4) {
if (dice[0]==4 || dice[1]==4 || dice[2]==4 || dice[3]==4 || dice[4]==4){
totalfours+= dice[0] + dice[1] + dice[2] + dice[3] + dice[4];
}
}
//Determine addition of fives
else if (category ==5) {
if (dice[0]==5 || dice[1]==5 || dice[2]==5 || dice[3]==5 || dice[4]==5){
totalfives+= dice[0] + dice[1] + dice[2] + dice[3] + dice[4];
}
}
//Determine addition of sixes
else if (category ==6) {
if (dice[0]==6 || dice[1]==6 || dice[2]==6 || dice[3]==6 || dice[4]==6){
totalsixs+= dice[0] + dice[1] + dice[2] + dice[3] + dice[4];
}
}
//Determine addition if three of a kind
else if (category ==7) {
threeofakind += dice[0]+dice[1]+dice[2]+dice[3]+dice[4];
}
//Determine addition if four of a kind
else if (category ==8) {
fourofakind += dice[0]+dice[1]+dice[2]+dice[3]+dice[4];
}
//Assign 25 points to full house
else if (category ==9) {
fullHouse += 25;
}
//Assign 30 points to small straight
else if (category ==10) {
smallStraight += 30;
}
//Assign 40 points to large straight
else if (category ==11) {
largeStraight += 40;
}
//Assign 50 points to yahtzee
else if (category ==12) {
yahtzee += 50;
}
//Determine addition of all dice for chance
else if (category ==13) {
chance += dice[0]+dice[1]+dice[2]+dice[3]+dice[4];
}//Assign zero to scratch
else if (category ==14) {
scratch += 0;
}
//Displays the current points
cout << "1 - Ones: " << totalones << " ";
cout << "2 - Twos: " << totaltwos << " ";
cout << "3 - Threes: " << totalthrees << " ";
cout << "4 - Fours: " << totalfours << " ";
cout << "5 - Fives: " << totalfives << " ";
cout << "6 - Sixes: " << totalsixs << " ";
cout << "7 - 3 of a Kind: " << threeofakind << " ";
cout << "8 - 4 of a Kind: " << fourofakind << " ";
cout << "9 - Full House: " << fullHouse << " ";
cout << "10 -Small Straight: " << smallStraight << " ";
cout << "11 -Large Straight: " << largeStraight << " ";
cout << "12 -Yahtzee: " << yahtzee << " ";
cout << "13 -Chance: " << chance << " ";
cout << "14 - Scratch: " << scratch << " ";
cout << " ";

round++; }
//Determines the final score with bonus
if ( (totalones + totaltwos + totalthrees + totalfours + totalfives + totalsixs) > 62 ){
finalscore = totalones + totaltwos + totalthrees + totalfours + totalfives + totalsixs + threeofakind + fourofakind + fullHouse + smallStraight + largeStraight + yahtzee + chance + 35 ;
}
//Determine the final score without bonus
else if ( (totalones + totaltwos + totalthrees + totalfours + totalfives + totalsixs) < 63 ) {
finalscore = totalones + totaltwos + totalthrees + totalfours + totalfives + totalsixs + threeofakind + fourofakind + fullHouse + smallStraight + largeStraight + yahtzee + chance;
}
cout << "Congratulations, your final score is " << " " << finalscore << " " ;

return 0;
}
//THE END

Explanation / Answer

#The mistake you are doing if any of the value on dice is 1 you are adding it.
if (category == 1) {
   totalones = 0;
   for (int i = 0; i <= 4; i++){
       if (check(dice[i],1) == true)
           totalones += 1;
   }
}

if (category == 2) {
   totaltwos = 0;
   for (int i = 0; i <= 4; i++){
       if (check(dice[i],2) == true)
           totaltwos += 2;
   }
}

if (category == 3) {
   totalthrees = 0;
   for (int i = 0; i <= 4; i++){
       if (check(dice[i],3) == true)
           totalthrees += 3;
   }
}

if (category == 4) {
   totalfours = 0;
   for (int i = 0; i <= 4; i++){
       if (check(dice[i],4) == true)
           totalfours += 4;
   }
}

if (category == 5) {
   totalfives = 0;
   for (int i = 0; i <= 4; i++){
       if (check(dice[i],5) == true)
           totalfives += 5;
   }
}

if (category == 6) {
   totalsixs = 0;
   for (int i = 0; i <= 4; i++){
       if (check(dice[i],6) == true)
           totalthrees += 6;
   }
}

// Write this function out main()
bool check(int val,int tar){
   if (tar == val) return true;
   return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote