Question

If a player rolls 2 dice, how do i keep track of the number of times...

If a player rolls 2 dice, how do i keep track of the number of times a player rolls those 2 dice?

Please code in C

Please show example code

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You can create an array of structure to hold the info about every roll

C code :

#include <stdio.h>
// Define a structure to hold the dice rolls
struct dice_roll
{
    int dice1_roll;
    int dice2_roll;
    int total;
};

int main()
{
    int i;
    // Now we create an array of type dice_roll that will hold all the info about them
    struct dice_roll arr[3];
      
    for(i=0;i<3;i++)
    {  
        printf("\nInfo about roll %d ",i+1);
        printf("\nEnter the value on dice 1 : ");  
        scanf("%d",&arr[i].dice1_roll);  
        printf("\nEnter the value on dice 2 : ");
        scanf("%d",&arr[i].dice2_roll);
        arr[i].total = arr[i].dice1_roll + arr[i].dice2_roll;
    }
    // Now we display the results
    for(i=0;i<3;i++)
    {   printf("\nInfo about roll %d ",i+1);
        printf("\nValue on dice 1 = %d",arr[i].dice1_roll);
        printf("\nValue on dice 2 = %d",arr[i].dice2_roll);
       printf("\nTotal value on the two dice = %d ",arr[i].total);
    }
}


Output :

weWv8fGYD4h+gAAAABJRU5ErkJggg==

Add a comment
Know the answer?
Add Answer to:
If a player rolls 2 dice, how do i keep track of the number of times...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT