repl.it
@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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;

class MainClass {
  public static void Main (string[] args) {
		Random r = new Random();
		int guess;
    int numbers;
    int tries = 0;
    string blah = "try";
		Console.WriteLine("Choose a difficulty: easy, normal, hard");
		string lel = Console.ReadLine();
		if (lel.Equals("easy", StringComparison.OrdinalIgnoreCase)){
			int randnumber = (r.Next(1, 11));
			Console.WriteLine("I'm thinking of a number 1 - 10");
		}
		if (lel.Equals("normal", StringComparison.OrdinalIgnoreCase{
			randnumber = (r.Next(1,21));
			Console.WriteLine("Hello! I'm thinking of a number 1 - 20");
		}
		if (lel.Equals("hard", StringComparison.OrdinalIgnoreCase)){
			randnumber = (r.Next(1,51));
			Console.WriteLine("Hello! I'm thinking of a number 1 - 50");
		}
    
    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;
      }
    }
  }
}
?