Quick help with a Uni assignment

For Uni I have been asked to make a Yahtzee game in C++ following some instruction...all was going well up to a point where I have been asked to iterate a loop 13 times (one for each of the possible dice rolls combos in Yahtzee)

Here is my current source code: There may be other issues I am not aware of within this code - there are also the sections blocked/commented out with a '//' or a '*/ /*' arrangement.

I specifically need assistance with '//Hold and/or Re-Roll', '//iterate loop 13 times' and '//check for bonus'


thanks in advance.


#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>

using namespace std;

int main()
{

int sum = 0;
int num = 5;
int roll[5] = {0};
int count[6] = {0};
int score[13] = {0};
int h = 1;
int r = 0;
int holdorroll, holdorroll2, holdorroll3, holdorroll4, holdorroll5;


//Generate randoms for dice rolls

srand(time(0));


cout << "Were playing Yahtzee..." << "Lets get going";
cout << "The dice roll was... " << endl;
std::cout << (rand() % 6 + 1) << std::endl;
std::cout << (rand() % 6 + 1) << std::endl;
std::cout << (rand() % 6 + 1) << std::endl;
std::cout << (rand() % 6 + 1) << std::endl;
std::cout << (rand() % 6 + 1) << std::endl;

/*
cout << "Please enter 5 numbers" << endl;
for (int i = 0; i < 5; i++)

cin >> roll [i];
for (int i = 0; i < 5; i++)

sum += roll[i];
*/

//Hold and/or Re-Roll

cout << " " << endl;

cout << "To select which die to hold and which to re-roll, key in 'h' for hold and 'r' for re-roll int ths same order they appear on your screen. To continue key return. " << endl; // Enter in the hold/re-roll commands ...

cin >> holdorroll >> holdorroll2 >> holdorroll3 >> holdorroll4 >> holdorroll5;


//iterate loop 13 times





//check for bonus




//Scoring.

score[0] = count[0]*1;
score[1] = count[1]*2;
score[2] = count[2]*3;
score[3] = count[3]*4;
score[4] = count[4]*5;
score[5] = count[5]*6;

for (int i = 0; i <5; i++)
{ if (count[i]/3 >= 1)
score[6] = sum;
}
for (int i = 0; i <5; i++)
{ if (count[i]/4 >= 1)
score[7] = sum;
}
for (int i = 0; i <5; i++)
{ if (count[i]/3 >=1 && count[i]/2 >=1)
score[8] = 25;
}
for (int i = 0; i <5; i++)
{ if ((count[0]*count[1]*count[2]*count[3]) == 1 ||
(count[1]*count[2]*count[3]*count[4]) == 1 ||
(count[2]*count[3]*count[4]*count[5]) == 1)
score[9] = 30;
}
{ if ((count[0]*count[1]*count[2]*count[3]*count[4]) == 1 ||
(count[1]*count[2]*count[3]*count[4]*count[5]) == 1)
score[10] = 40;
}
for (int i = 0; i < 5; i++)
{ if (count[i]/5 >= 1)
score[11] = 50;
}
score[12] = sum;

//output of scores

cout << setw(30) << " Yahtzee Results " << endl;
cout << "Ace's" << setw(14) << score[0] << endl;
cout << "Two's" << setw(14) << score[1] << endl;
cout << "Three's" << setw(12) << score[2] << endl;
cout << "Four's" << setw(13) << score[3] << endl;
cout << "Five's" << setw(13) << score[4] << endl;
cout << "Six's" << setw(14) << score[5] << endl;
cout << "Three of a Kind" << setw(4) << score[6] << endl;
cout << "Four of a Kind" << setw(5) << score[7] << endl;
cout << "Full House" << setw(9) << score[8] << endl;
cout << "Small Straight" << setw(5) << score[9] << endl;
cout << "Large Straight" << setw(5) << score[10] << endl;
cout << "YAHTZEE" << setw(12)<< score[11]<< endl;
cout << "Chance" << setw(13)<< score[12]<< endl;
cout << setw(30) << "******************************" << endl;



}
Would you first modify your post and put [code]code tags[/code] around your code so we can clearly see the syntax highlighting?

As for the 13 times, think of all the possible dice rolls, maybe store them in an array or two (or better yet find a pattern) and then iterate with a loop of your choice, such as the for loop.
Topic archived. No new replies allowed.