Design an application that uses the C# random generator to randomly roll a six face dice ( no 1 - no 6) . If the user rolled a 3, the user gets to roll the six face die again. You must use a switch statement to write the result /s of the random dice roll/s to the screen. Hint: You should have nested switches in your program
using System;
class HelloWorld {
static void Main() {
Random rand = new Random();
while(true)
{
int a = rand.Next(1, 7); // generating the Random number between 1
and 6
switch(a)
{
case 1: Console.WriteLine("The user has rolled one (" + a + ")");
break;
case 2: Console.WriteLine("The user has rolled two (" + a + ")");
break;
case 3: Console.WriteLine("The user has rolled three (" + a + ")");
break;
case 4: Console.WriteLine("The user has rolled four (" + a + ")");
break;
case 5: Console.WriteLine("The user has rolled five (" + a + ")");
break;
case 6: Console.WriteLine("The user has rolled six (" + a + ")");
break;
}
if(a != 3) // if it is 3 the user will roll down again
{
break;
}
}
}
}
OUTPUT :
Get Answers For Free
Most questions answered within 1 hours.