Nor
CS0120 - Object refrence required for the non static field, method, or property "object.Equals(obj)"
Hello! I am a self learning programmer beginning with c#.
I am trying to code a randomized Math Quiz in a Console app, and i am currently trying to validate the user input and then have it print "Correct" or "False" depending on the answer.
Now, im not sure as how to approach this, but i have a general idea of the code and i coded it, its just that i have no idea how to make it check whether the answer was correct, and it gives me the aforementioned error.
Heres my code:
// START HERE
Console.WriteLine("Welcome to this Math Quiz!");
Console.WriteLine("This is your first question");
// RNG
Random rnd = new Random();
float random1 = rnd.Next(-100, 100);
float random2 = rnd.Next(-100, 100);
Console.WriteLine("{0} + {1}?", random1, random2);
// Checks if answer is correct
float answer = random1 + random2;
Convert.ToBoolean(answer);
if (Console.ReadLine(Equals(answer)))
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("False!");
}
39 replies