Why is the if statement on Visual C# not being evaluated properly? -
i'm trying make times table console application in visual studio 2015 community using visual c#, if statement isn't being evaluated properly. started debug (test) console application, if statement wasn't evaluated in last 3 questions. can help? here code:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace xtables { class program { static void main(string[] args) { console.writeline("welcome xtables"); console.writeline("in application, you'll have answer questions from"); console.writeline("the times table 12"); console.writeline("good luck!"); //question 1 console.writeline("what 1 x 6"); string useranswer = console.readline(); if (useranswer == "6") { string message = "correct"; console.writeline(message); } else { string message = "incorrect"; console.writeline(message); } //question 2 console.writeline("what 2 x 3"); console.readline(); if (useranswer == "6") { string message = "correct"; console.writeline(message); } else { string message = "incorrect"; console.writeline(message); } //question 3 console.writeline("what 8 x 9"); console.readline(); if (useranswer == "72") { string message = "correct"; console.writeline(message); } else { string message = "incorrect"; console.writeline(message); } //question 4 console.writeline("what 5 x 6"); console.readline(); if (useranswer == "30") { string message = "correct"; console.writeline(message); } else { string message = "incorrect"; console.writeline(message); } //question 5 console.writeline("what 4 x 6"); console.readline(); if (useranswer == "24") { string message = "correct"; console.writeline(message); } else { string message = "incorrect"; console.writeline(message); } } }
}
in first question, have this:
console.readline();
when want this:
useranswer = console.readline();
edit further explanation
because answer second question same answer first, may appear working. (you may typing same answer twice.) in reality, it's not last 3 questions aren't working; first question doing want.
Comments
Post a Comment