Skip to content

Instantly share code, notes, and snippets.

@Gimanua
Last active September 26, 2017 11:23
Show Gist options
  • Save Gimanua/33d2736274c94f3cd3383d81df3631e7 to your computer and use it in GitHub Desktop.
Save Gimanua/33d2736274c94f3cd3383d81df3631e7 to your computer and use it in GitHub Desktop.
C# Gissningsspel
using System;
class Program
{
static void Main(string[] args)
{
Random rnd = new Random();
int numb = rnd.Next(1, 101);
int guess, guesses = 0;
Console.WriteLine("Gissa på ett tal mellan 1-100");
do
{
guess = int.Parse(Console.ReadLine());
guesses++;
if (guess == numb)
Console.WriteLine("Grattis, du gissade rätt!");
else if (guess < numb)
Console.WriteLine("Du gissade för lågt, försök igen.");
else
Console.WriteLine("Du gissade för högt, försök igen.");
} while (guess != numb);
Console.WriteLine("Du gissade: " + guesses + " gånger.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment