Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GuessTheNumberGameSimplified {
- class Program {
- static void Main(string[] args) {
- //The correct answer
- int answer = 8;
- //Console.WriteLine(answer); TOGGLE FOR CHECKING PURPOSES
- //Initial message.
- Console.WriteLine("Number Guessing Game \nI am thinking of a number between 1 and 10 - can you guess which it is?");
- //The users string input is converted to an integer and stored in the variable userGuess
- int userGuess = 0;
- //To show that it is stored correctly
- //Console.WriteLine(userGuess); TOGGLE FOR CHECKING PURPOSES
- //Variable to tell the program if it should perform the do-loop or jump to end.
- bool GameOver = false;
- //Program will always execute this as long as GameOVer has value false.
- do
- {
- //Program should execute this while GameOver has value false.
- while (GameOver == false) {
- //The user should be able to guess
- Console.WriteLine("Enter your guess:");
- userGuess = Convert.ToInt32(Console.ReadLine());
- //if the user guesses a number that is too high they should get this message:
- if (userGuess > answer) {
- Console.WriteLine($"{userGuess} is not correct, try a lower number!");
- GameOver = false;
- }
- //if the user guesses a number that is too low they should get this message:
- else if (userGuess < answer) {
- Console.WriteLine($"{userGuess} is not correct, try a higher number!");
- GameOver = false;
- }
- //if the user guesses the correct number they should get this:
- else {
- //Win message
- Console.WriteLine("Correct, you win!");
- do {
- //Option to play again
- Console.WriteLine("Press 1 to play again, or 2 to quit");
- //new user input - stored as int in a new variable.
- int playAgain = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine(playAgain);
- //execute if player wants to play again
- if (playAgain == 1) {
- break;
- }
- //execute if player chooses to not play again.
- else {
- GameOver = true;
- }
- }
- while (GameOver == false);
- }
- }
- }
- while (GameOver == false);
- //End of program message.
- Console.WriteLine("Thank you for playing!");
- //Makes the console stay open after game is completed.
- Console.ReadLine();
- //DONT TOUCH THESE!! END OF PROGRAM
- }
- }
- }
- //DONT TOUCH THESE!! END OF PROGRAM
Add Comment
Please, Sign In to add comment