Hello!
I just started learning C# via online youtube videos and am trying to apply some learnings to make a small dice game with the below code but am having issues getting the dice roll to return as an integer and keep getting the result as 1. Was hoping for some help and feedback on where I'm going wrong, please!
I just started learning C# via online youtube videos and am trying to apply some learnings to make a small dice game with the below code but am having issues getting the dice roll to return as an integer and keep getting the result as 1. Was hoping for some help and feedback on where I'm going wrong, please!
C#:
using System;
using System.Collections.Generic;
namespace Dice_game
{
class Dice_game
{
static void Main(string[] args)
{
Random numberGen = new Random();
Console.WriteLine("Hello. Let's play a game. You will roll 2 dice by pressing enter. \nGuess how many rolls it will take to get the sum of those numbers that you also choose.");
Console.WriteLine("What's the sum you're aiming for?");
int sumGuess = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("How many rolls do you think it will take to hit?");
int rollCount = Convert.ToInt16(Console.ReadLine());
int dice1 = 0;
int dice2 = 1;
int attempt = 0;
int sum = (dice1+dice2);
Console.WriteLine("Press enter to roll the dice.");
while (sum != sumGuess) {
Console.ReadKey();
dice1 = numberGen.Next(1,7);
dice2 = numberGen.Next(1,7);
Console.WriteLine ("You rolled " + dice1 + " and " + dice2 + " for a total of " + sum);
attempt++;
}
Console.WriteLine("You guessed it would take " + rollCount + " attempts to roll your estiamted sum of " + sumGuess);
Console.WriteLine("It took you " + attempt + " attempts to roll " + sum);
// Wait before closing
Console.ReadKey();
}
}
}
Last edited by a moderator: