Created
June 2, 2015 21:10
-
-
Save MrAwesomeness/6196354b6643faaad801 to your computer and use it in GitHub Desktop.
C# guess a number from 1 to 100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Random rand = new Random(); | |
int guess = 0; | |
string welcome = "Guess a number between 1 and 100"; | |
int num = rand.Next(1,100); | |
Console.WriteLine(welcome); | |
int i = 0; | |
while(guess != num) | |
{ | |
try | |
{ | |
guess = Convert.ToInt32(Console.ReadLine()); | |
if (guess > num) | |
{ | |
Console.WriteLine("Too High"); | |
} | |
else | |
{ | |
Console.WriteLine("Too Low"); | |
} | |
} | |
catch | |
{ | |
Console.WriteLine("Guess must be a number"); | |
i--; | |
} | |
i++; | |
} | |
Console.WriteLine("Congrats, it took you " + i + " tries"); | |
Console.ReadLine(); | |
} | |
} | |
} |
it doesn't work at all, did you even try it before publishing ?
it doesn't work at all, did you even try it before publishing ?
just add 1 in the parenthesis of new Random()
You can when user say exit it will say bye and guess game exit and final number will be shown
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
COOL