@CycleWeeb/

number guesser

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;

class MainClass {
  public static void Main (string[] args) {
    Random r = new Random();
    int guess;
    int randnumber = (r.Next(1, 11));
    int tries = 0;
    string blah = "try";
    Console.WriteLine("Hello! I'm thinking of a number 1 - 10");
    while(true){
      guess = int.Parse(Console.ReadLine());
      if(guess > randnumber){
        Console.WriteLine("Guess lower");
        tries++;
      }
      else if(guess < randnumber){
        Console.WriteLine("Guess higher");
        tries++;
      }
      else if(guess == randnumber){
        tries++;
        if(tries > 1){
          blah = "tries";
        }
        Console.WriteLine("You got it! Congrats! And you took {0} {1}", tries, blah);
        break;
      }
    }
  }
}