I'm new to C#
learning, I followed a tutorial and then tried throwing an error message myself for every time my IF statement is false. here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string SecretWord = "Banana";
string Guess = "";
int GuessCount = 0;
int GuessLimit = 4;
bool OutOfGuesses = false;
while (Guess != SecretWord && !OutOfGuesses)
{
if (GuessCount < GuessLimit)
{
Console.Write("Enter a Guess: ");
Guess = Console.ReadLine();
GuessCount++;
} else
{
OutOfGuesses = true;
}
if (Guess != SecretWord)
{
Console.WriteLine("Wrong Guess");
}
}
if (OutOfGuesses)
{
Console.WriteLine("You Lose");
} else {
Console.WriteLine("You Win!");
}
Console.ReadLine();
}
}
}
The output is this:
Enter a Guess: dsadasd
Wrong Guess
Enter a Guess: dsdasd
Wrong Guess
Enter a Guess: dasdas
Wrong Guess
Enter a Guess: dasdas
Wrong Guess
Wrong Guess
You Lose
I can't figure out why I am getting double "Wrong Guess" at the end. does anyone know why?
Aucun commentaire:
Enregistrer un commentaire