Little help with programming.

Users who are viewing this thread

bass_man1989

Active Member
Messages
1,105
Reaction score
0
Tokenz
0.00z
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=&quot]ROLL #3[/FONT]
[FONT=&quot]Dice 1: 1[/FONT]
[FONT=&quot]Dice 2: 1[/FONT]
[FONT=&quot]Dice 3: 3[/FONT]
[FONT=&quot]Dice 4: 3[/FONT]
[FONT=&quot]Dice 5: 1[/FONT]

[FONT=&quot]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.
 
  • 11
    Replies
  • 316
    Views
  • 0
    Participant count
    Participants list

sierrabravo

Active Member
Messages
4,174
Reaction score
0
Tokenz
0.00z
whoa! holy fuck... i had a programming class in high school, they told us to make a game of blackjack that would randomly deal cards and bust you over 21... i was the only one where the computer popped up and said "fuckwit..." i sucked at it
 

bass_man1989

Active Member
Messages
1,105
Reaction score
0
Tokenz
0.00z
I don't think I'm horrible (only had a few little assignments so far) but I have a nasty habit of over-complicating things.
 

Mystic

OTz's Typo Scouser
Messages
12,025
Reaction score
67
Tokenz
117.19z
....hell i learned programing when you had to use a tape to rewind on the apple 3 dos and the word 'run' was used a lot lmao

BM...good luck with that, I hope someone can help you.
 

bass_man1989

Active Member
Messages
1,105
Reaction score
0
Tokenz
0.00z
It needs to say the total number of like dice. For example if you have rolled 3 2's. It would need to output "You have rolled 3 2's.
 

bass_man1989

Active Member
Messages
1,105
Reaction score
0
Tokenz
0.00z
I'm getting it to where I can make it tell me how many like numbers I have. Still trying to figure out how to make it tell me what those numbers are.
 

bass_man1989

Active Member
Messages
1,105
Reaction score
0
Tokenz
0.00z
I hate to self-bump, but this damn thing is making me want to put my head through the wall. I'm so fucking close, just that one little part.
 
78,874Threads
2,185,387Messages
4,959Members
Back
Top