Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCameron Nazarko
810 PointsI'm unable to find a solution to lowercase my input. C#
namespace Quiz { class Program { static void Main(string[] args) { int score = 0;
Console.WriteLine("What is 5 + 5");
Console.WriteLine("A) 2 B) 10 C) 20");
if (Console.ReadLine() == "B")
{
Console.WriteLine("Good Job!");
score++;
}
Console.WriteLine("What is 6 + 6");
Console.WriteLine("A) 2 B) 10 C) 12");
if (Console.ReadLine() == "C")
{
Console.WriteLine("Good Job!");
score++;
}
Console.WriteLine("What is 7 + 7");
Console.WriteLine("A) 14 B) 10 C) 12");
if (Console.ReadLine() == "A")
{
Console.WriteLine("Good Job!");
score++;
}
Console.WriteLine("Your score is: {0}", score);
Console.ReadLine();
}
}
}
I'm trying to have if(Console.ReadLine() == "C" || "b") { Console.WriteLine("Good Job!"); score++ }
I'm not sure how to get this to work though. I've tried doing .ToLower as well but it doesn't seem to work. Or maybe I'm just doing it wrong, Idk. If anyone could help that'd be great.
1 Answer
Steven Parker
231,264 PointsThe "ToLower" is a good idea, but be sure you compare it only with lower-case strings!
Also, when you combine tests with boolean logic, each side of the combiner must be a complete expression:
// so instead of this:
if (Console.ReadLine() == "C" || "b")
// you would need something like this:
var answer = Console.ReadLine().ToLower();
if (answer == "c" || answer == "b")