Question: C program that will roll 2 dice until we roll a 7. The program must use at least one static variable. I have it set

C program that will roll 2 dice until we roll a 7. The program must use at least one static variable. I have it set up to where we roll the dice until we get 7, although I need to include the frequency that a particular diceSum occurs...

Example of desired output:

You rolled a 3 and a 3:

Frequency of 6: 1

You rolled a 2 and a 4:

Frequency of 6: 2

You rolled a 2 and a 1:

Frequency of 3: 1

You rolled a 6 and a 1:

Frequency of 7: 1

..........

Here is what I have so far.

#include #include #include #include

int main() { //variables int dice1, dice2, diceSum; srand(time(NULL));

do{

dice1 = (rand() % 6) + 1; dice2 = (rand() % 6) + 1; diceSum = dice1 + dice2; printf("You rolled a %d and a %d ", dice1, dice2); printf("%d ", diceSum);

}while (diceSum != 7);

return 0; }

The program also needs to reset the diceSum at the end and give the user a chance to do another run until some exit variable is pressed

i.e. at the end of one run: "press a to go again or x to exit"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!