I am trying to make a simple dice rolling program that will roll a set amount of dice and set amount of sides, but I can't find an adequate explanation of the use of Random to put the random part in. Can someone help me with this?
using System;
class Roll_The_Dice
{
static void Main()
{
int numberInteger, sidesInteger, modifierInteger, rollsInteger;
string answerString;
do
{
Console.Clear();
Console.WriteLine();
Console.WriteLine("*** * Roll the Dice * ***");
Console.WriteLine();
Console.Write("Enter Number of Dice : ");
int.TryParse(Console.ReadLine(), out numberInteger);
Console.Write("Enter Number of Sides: ");
int.TryParse(Console.ReadLine(), out sidesInteger);
Console.WriteLine();
do //This loop I want to take the above inputs and use them for 1.) sides int for max sides 2.) use the number of dice to continue until out of dice
//and 3.) add all the rolls together then add the modifier. My friends managed this quite easily in C++.
{
Random rollInteger = new Random();
Console.WriteLine("Your roll is " + rollInteger.Next(1, sidesInteger).ToString() + "!");
numberInteger = numberInteger - 1;
} while (numberInteger > 0);
Console.WriteLine();
do
{
Console.Write("Roll again (Y/N)? ");
answerString = Console.ReadLine().ToUpper();
} while (answerString != "Y" && answerString != "N");
} while (answerString == "Y");
Console.WriteLine();
Console.Write("Thanks for rolling with me! Press Enter to exit!");
Console.WriteLine();
}
} //End Class
using System;
class Roll_The_Dice
{
static void Main()
{
int numberInteger, sidesInteger, modifierInteger, rollsInteger;
string answerString;
do
{
Console.Clear();
Console.WriteLine();
Console.WriteLine("*** * Roll the Dice * ***");
Console.WriteLine();
Console.Write("Enter Number of Dice : ");
int.TryParse(Console.ReadLine(), out numberInteger);
Console.Write("Enter Number of Sides: ");
int.TryParse(Console.ReadLine(), out sidesInteger);
Console.WriteLine();
do //This loop I want to take the above inputs and use them for 1.) sides int for max sides 2.) use the number of dice to continue until out of dice
//and 3.) add all the rolls together then add the modifier. My friends managed this quite easily in C++.
{
Random rollInteger = new Random();
Console.WriteLine("Your roll is " + rollInteger.Next(1, sidesInteger).ToString() + "!");
numberInteger = numberInteger - 1;
} while (numberInteger > 0);
Console.WriteLine();
do
{
Console.Write("Roll again (Y/N)? ");
answerString = Console.ReadLine().ToUpper();
} while (answerString != "Y" && answerString != "N");
} while (answerString == "Y");
Console.WriteLine();
Console.Write("Thanks for rolling with me! Press Enter to exit!");
Console.WriteLine();
}
} //End Class