bass_man1989
Active Member
I'm in a programming class and I've got my first assignment. We have to make a game of Yahtzee. I've got the whole game programmed except one part. After a set of rolls we have to make an output that would look like this:
[FONT="]ROLL #3[/FONT]
[FONT="]Dice 1: 1[/FONT]
[FONT="]Dice 2: 1[/FONT]
[FONT="]Dice 3: 3[/FONT]
[FONT="]Dice 4: 3[/FONT]
[FONT="]Dice 5: 1[/FONT]
[FONT="]You have rolled 3 1's[/FONT]
I've probably over complicated the program by making this set of instructions for each roll (sets each die# to a random number at the beginning of the program):
cout << endl << endl << endl;
cout << "ROLL #2" << endl;
cout << "Dice 1: " << die1 << endl
<< "Dice 2: " << die2 << endl
<< "Dice 3: " << die3 << endl
<< "Dice 4: " << die4 << endl
<< "Dice 5: " << die5 << endl << endl;
//Asks to discard or hold dice for roll #2
{
cout << "Hold Dice 1? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die1 = (rand() % 6) + 1;
}
cout << "Hold Dice 2? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die2 = (rand() % 6) + 1;
}
cout << "Hold Dice 3? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die3 = (rand() % 6) + 1;
}
cout << "Hold Dice 4? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die4 = (rand() % 6) + 1;
}
cout << "Hold Dice 5? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die5 = (rand() % 6) + 1;
}
}
//End of code for roll #2.
But it works. The only probably I'm really having is how to make it say "You have rolled (so many of a certain number of dice)." I'm going to keep working on it but if anyone has any idea on how to do that part it would be greatly appreciated.
Edit: forgot to mention it's C++, but if you're helping me you probably knew that from the code.
[FONT="]ROLL #3[/FONT]
[FONT="]Dice 1: 1[/FONT]
[FONT="]Dice 2: 1[/FONT]
[FONT="]Dice 3: 3[/FONT]
[FONT="]Dice 4: 3[/FONT]
[FONT="]Dice 5: 1[/FONT]
[FONT="]You have rolled 3 1's[/FONT]
I've probably over complicated the program by making this set of instructions for each roll (sets each die# to a random number at the beginning of the program):
cout << endl << endl << endl;
cout << "ROLL #2" << endl;
cout << "Dice 1: " << die1 << endl
<< "Dice 2: " << die2 << endl
<< "Dice 3: " << die3 << endl
<< "Dice 4: " << die4 << endl
<< "Dice 5: " << die5 << endl << endl;
//Asks to discard or hold dice for roll #2
{
cout << "Hold Dice 1? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die1 = (rand() % 6) + 1;
}
cout << "Hold Dice 2? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die2 = (rand() % 6) + 1;
}
cout << "Hold Dice 3? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die3 = (rand() % 6) + 1;
}
cout << "Hold Dice 4? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die4 = (rand() % 6) + 1;
}
cout << "Hold Dice 5? (y/n): ";
cin >> answer;
if (answer == 'N' || answer == 'n')
{
die5 = (rand() % 6) + 1;
}
}
//End of code for roll #2.
But it works. The only probably I'm really having is how to make it say "You have rolled (so many of a certain number of dice)." I'm going to keep working on it but if anyone has any idea on how to do that part it would be greatly appreciated.
Edit: forgot to mention it's C++, but if you're helping me you probably knew that from the code.