Question

Create a dice simulator in C#. Comment code to explain what is the functions are doing....

Create a dice simulator in C#. Comment code to explain what is the functions are doing. The simulator must roll the dice 6 times and it must add the 3 highest roll values. So, say it simulates: 4 4 3 2 1 5 after rolling six times. The total would be 13 (4+4+5=13). 4,4,5, are the largest numbers out of the 6 values. Add the three largest numbers together. Repeat this 6 different times.

If the random dice simulator simulates the outcomes below it should output: 13, 13, 15, 12, 16, 12.

1) 4 4 3 2 1 5

2) 2 3 6 1 3 4

3) 5 3 1 4 6 2  

4) 4 2 2 1 1 6

5) 5 4 5 6 3 1

6) 1 2 4 5 3 2

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

//c# program

using System.IO;
using System;

class Program
{ //function to generate random number
public static int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
//main driver function
static void Main()
{
int first=0,second=0,third=0;
int sum=0;
for(int i=0;i<6;i++){
first=0;second=0;third=0;
for(int j=0;j<6;j++){
int num = RandomNumber(1, 6) ;
if (num > first)
{
third = second;
second = first;
first = num;
}

else if (num > second)
{
third = second;
second = num;
}

else if (num > third)
third = num;
  
}
sum = first+second+third;
Console.WriteLine(sum);
}
  
}
}

Add a comment
Know the answer?
Add Answer to:
Create a dice simulator in C#. Comment code to explain what is the functions are doing....
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