Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- Console.WriteLine("Input your age.");
- int ageMinimum = 18;
- int age = InputNumber();
- if (age < ageMinimum)
- {
- Console.WriteLine("Your age too small than 18.");
- }
- else
- {
- Console.WriteLine("You're welcome.");
- PlayNumberGame();
- }
- }
- public static int InputNumber()
- {
- int number;
- bool isInput;
- do
- {
- isInput = !int.TryParse(Console.ReadLine(), out number);
- }
- while(isInput);
- return number;
- }
- public static void PlayNumberGame()
- {
- int numberMinimum = 0;
- int numberMaximum = 100;
- Random random = new Random();
- bool isPlaying = true;
- int numberChoose;
- int numberRandom;
- do
- {
- PrintMenu();
- numberChoose = InputNumber();
- switch(numberChoose)
- {
- case 0:
- numberRandom = random.Next(numberMinimum, numberMaximum);
- Console.WriteLine("Input a number from " + numberMinimum + " to " + numberMaximum + ".");
- numberChoose = InputNumber();
- if (numberChoose == numberRandom)
- Console.WriteLine("You win!!!!");
- else
- Console.WriteLine("You loose.");
- break;
- case 1:
- isPlaying = false;
- Console.WriteLine("Exit from game.");
- break;
- }
- }
- while (isPlaying);
- }
- public static void PrintMenu()
- {
- Console.WriteLine("\n0. Play Number Game.");
- Console.WriteLine("1. Exit.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment