Question

I am having some trouble writing this program. In C language Write a program which asks...

I am having some trouble writing this program.

In C language Write a program which asks user 1) number of sets (integer input), followed by 2) number of sides of a dice (integer input) and 3) number of dices (integer input).

number of sets mean how many times this process is going to repeat, number of sides mean total number of sides in a dice (usually 6) and number of dices mean how many number of dices we’re going to roll together and sum the resultant dice roll together to return one set.

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

#include <stdio.h>
#include <stdlib.h>

int main()

{
// declaring variables
int sets, sides, dices, roll, i, j;
srand(time(NULL));
  
// taking user input
printf("Enter the number of sets: ");
scanf("%d", &sets);
printf("Enter the number of sides of a die: ");
scanf("%d", &sides);
printf("Enter the number of dice: ");
scanf("%d", &dices);
  
// looping for number of sets
for(i=1; i<=sets; i++)
{
int total = 0; // rolling dice and getting sum
for(j=1; j<=dices; j++)
{
total += (rand() % sides) + 1;
}
  
// printing set data
printf("\nSet %d got the sum = %d", i, total);
}
return 0;
}

// -- Please up vote or comment if you have any doubts. Happy Learning!

Add a comment
Know the answer?
Add Answer to:
I am having some trouble writing this program. In C language Write a program which asks...
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
  • I am trying to program a dice game in Visual Studios c++ but am having trouble....

    I am trying to program a dice game in Visual Studios c++ but am having trouble. The program allows the user to choose the number of rolls, not exceeding 100,000. I am trying to print out the number of times each number(1-6) was rolled, but it's not working. What am I doing wrong? The link below is a copy of my code. https://docs.google.com/document/d/1baKfnof4pjdQ4905hwXluFtbcA1Fs7QESMQKy45xdpE/edit

  • I am having trouble figuring out what should go in the place of "number" to make...

    I am having trouble figuring out what should go in the place of "number" to make the loop stop as soon as they enter the value they put in for the "count" input. I am also having trouble nesting a do while loop into the original while loop (if that is even what I am supposed to do to get the program to keep going if the user wants to enter more numbers???) I have inserted the question below, as...

  • I need help writing a C programming code. I am trying to create a program that...

    I need help writing a C programming code. I am trying to create a program that returns ANY given number's decimal value as an Integer (Whole number). Examples: User input: 0.35 Output: 35 User input: 1.465 Output: 465 User input: 10.6054 Output: 6054

  • use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers...

    use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers Write a program that generates n random numbers as follows: Asks the user to input a positive integer n Asks the user to input the maximum value (say m) for the integers to be generated. Write a program that generates the n numbers in the range 0 to m. The program stores the generated numbers in an array A[ Asks the user to enter...

  • I am writing C++ code, and I need help for this. Create a program that will...

    I am writing C++ code, and I need help for this. Create a program that will convert a decimal value into Roman numeral, and output the result. The program will ask for an integer input, assume all inputs are valid, and the program should not end unless the user tells you to. C++ code.

  • (CO 4 and 6) Create a program with a function named rollDice that will roll a...

    (CO 4 and 6) Create a program with a function named rollDice that will roll a dice as many times as the user asks and with a user specified number of sides. The function should return the roll of the die. The program should continue while the user presses Y.    Sample output: How many times do you want to roll the die? 5 How many sides does the die have: 6 You rolled 1 You rolled 2 You rolled...

  • C++ language I am having some trouble with user validation, can someone look at my code...

    C++ language I am having some trouble with user validation, can someone look at my code and tell me what I am doing wrong: char firstInital, lastInitial;    int userAge;    std::cout << "Program 1-2: Get user initials and age in days\n ";    std::cout << "-------------------------------------------------------------------------\n";    std::cout << "Please enter the first letter of your first name: \n " << flush;    std::cin >> firstInital;    std::cout << "Please enter the first letter of your last name: \n...

  • Use C++ language. Write a program that gives and takes advice on program writing. The program...

    Use C++ language. Write a program that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the...

  • Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game....

    Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game. It is played through dice. Rule for scoring The player who rolls higher number gets one point. If both players roll the same number, it is considered a draw and no one gets a point. Dice Specification There are two kinds of dice: normal die, represented by Die class. loaded die, represented by the loadedDie class. Classes Die class Die class has a member...

  • python program 6 Write an input validation loop that asks the user to enter a number...

    python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0    while  cnt != 5: print(cnt) cnt = cnt + 2

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