What's new

C# Number guessing game in C# pahelp po

HJT23

Enthusiast
Joined
Sep 14, 2021
Posts
13
Reaction
1
Points
41
patulong po ako paano to gawin
  1. The program will generate a random number from 1 to 100.
  2. The player will be given several chances to guess the number.
  3. The program gives a hint that the given number is lower or higher.
  4. If the player's guess is correct, give the player a single point.
  5. Tally the number of correct and wrong guesses that the player has made.
  6. After every round, display the tally (correct, wrong, and score)
  7. After a cycle the program will ask the user if he wants to continue playing.
This is a console project.

ito po yung code
using System;

namespace Practice_part_2
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
bool playAgain = true;
int min = 1;
int max = 10;
int guess;
int number;
int guesses;
int currentScore=0;
String response;

while (playAgain)
{
guess = 0;
guesses = 0;
currentScore = 0;
response = "";
number = random.Next(min, max + 1);

while (guess != number)
{
Console.WriteLine("Guess a number between " + min + " - " + max + " : ");
guess = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Guess: " + guess);

if (guess == number)
{
currentScore++;
}
else if (guess < number)
{
Console.WriteLine(guess + " is to low!");
}
else if(guess>number)
{

Console.WriteLine(guess + " is to high!");
}
guesses++;
}
Console.WriteLine("Number: " + number);
Console.WriteLine("YOU WIN!");
Console.WriteLine("Guesses: " + guesses);
Console.WriteLine("Score: " + currentScore);

Console.WriteLine("Would you like to play again (Y/N): ");
response = Console.ReadLine();
response = response.ToUpper();

if (response == "Y")
{
playAgain = true;
}
else
{
playAgain = false;
}
}

Console.WriteLine("Thanks for playing! ... I guess");

Console.ReadKey();
}
}
}
 
Last edited:

Similar threads

Back
Top