Hello I am writing a program in C# that takes a number and asks the user for a number, once the user enters the number the program checks if it matches the original number, if not it is supposed to tell the user if their answer was less or greater than, however my if statement is not working.
// Boolean if user passes
Boolean Userpassed;
// Declares Answer Variable
int answer = 6;
// Asks user for a number
Console.WriteLine("Enter a number between 1 and 10");
// Displays Message
Console.ReadLine();
// Takes User Input as String
string useranswer = Console.ReadLine();
// Declares integer for actual integer
int userinput;
// User string parsed to Int
userinput = Convert.ToInt32(Console.Read());
// Displays Message
Console.ReadLine();
// Checks if input is equal to answer
if (userinput == answer)
{
// User passes
Console.WriteLine("Congratulations, you have passed");
}
// Checks if input is greater than answer
else
if (userinput > answer)
{
// User Fails
Console.WriteLine("The actual answer is less than what you entered");
}
// Checks if input is less than answer
else
if (userinput < answer)
{
// User Fails
Console.WriteLine("The actual answer is greater than what you entered");
}
// Displays Message
Console.ReadLine();
The first if statement does not work as when I enter 6 it simply passes to the else loop. Then if I enter a different number it does not get past the second else loop. How do I fix this problem?
Aucun commentaire:
Enregistrer un commentaire