Advertisement
KodingKid

One of my first scripts in C# - Number Guessing Game - Throwback script #2

May 2nd, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Number Guessing Game
  7. {
  8.     class program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Random grn = new Random(); //grn = generated random number
  13.             int fn = grn.Next(-100, 100); //fn = final number
  14.             bool endgame = false;
  15.             do
  16.             {
  17.                 Console.WriteLine("Guess the randomly generated number between -100 and +100");
  18.                 string ga = Console.ReadLine(); //ga = given answer
  19.                 int pa = int.Parse(ga); //pa = processed answer
  20.                 if (pa > fn)
  21.                 {
  22.                     Console.WriteLine("Lower!!!");
  23.                     }
  24.                 else if (pa < fn)
  25.                 {
  26.                     Console.WriteLine("Higher!!!");
  27.                     }
  28.                 else if (pa == fn)
  29.                 {
  30.                     Console.WriteLine("YOU GUESSED CORRECTLY!!! YOU WON!!! :)");
  31.                     endgame = true;
  32.                     }
  33.                 Console.WriteLine();
  34.             } while endgame == false;
  35.             Console.WriteLine("Thanks for playing, bye!!! :D");
  36.             Console.WriteLine("Press any key to end the game now...");
  37.             Console.ReadKey(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement