โ” how do i include a range of numbers into a reply like 1-1000 for my thing

string correct = "well done. "; string wrong = "nope.try again. "; Console.WriteLine("Hello."); Console.Write("What is 2 + 2?"); string reply = Console.ReadLine(); if (reply == "4") Console.Write(correct); else if (reply == "5") Console.Write(wrong); i want it to be able to be so if i type in "6" or "52" or whatever i want it to say "nope try again"
28 Replies
SinFluxx
SinFluxxโ€ข17mo ago
I'm not sure what you're asking, where is it you're wanting the 1-1000 range to come into play?
๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ bb6
so when i answer 5 it says wrong but if i type 6 or 9 or 1 it just says nothing and i know why but idk how to fix it besides writing 100 strings which i know would be dumb
SinFluxx
SinFluxxโ€ข17mo ago
else if (reply =="5") you have this line, checking specifically if their answer is 5, you could just replace that line with: else so it works for all values other than 4
๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ bb6
ahhhh thank you ive done it now i just need to do one more thing and ive made my first working thing
SinFluxx
SinFluxxโ€ข17mo ago
that'll obviously only working if you've got two options (like here the condition is either correct or wrong), or as a final "check" where you've got more than two if/else if checks
๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ bb6
yeah i made it so once you get it wrong it says nope try again now im guessing i have to add another console writeline or soemtgihg
SinFluxx
SinFluxxโ€ข17mo ago
Do you mean add another line for when they get it wrong and need to guess again?
MODiX
MODiXโ€ข17mo ago
wewewwueirie
REPL Result: Success
string correct = "well done. "; // the strings
string wrong = "nope.try again.";

Console.WriteLine("Hello.");
Console.Write("What is 2 + 2?"); // the quesiton asked
string reply = Console.ReadLine();

if (reply == "4")
Console.Write(correct);

else
Console.Write(wrong); // if anything other than 4 then its wrong
string correct = "well done. "; // the strings
string wrong = "nope.try again.";

Console.WriteLine("Hello.");
Console.Write("What is 2 + 2?"); // the quesiton asked
string reply = Console.ReadLine();

if (reply == "4")
Console.Write(correct);

else
Console.Write(wrong); // if anything other than 4 then its wrong
Console Output
Hello.
What is 2 + 2?nope.try again.
Hello.
What is 2 + 2?nope.try again.
Compile: 528.385ms | Execution: 81.561ms | React with โŒ to remove this embed.
SinFluxx
SinFluxxโ€ข17mo ago
Well, you COULD, however when you add that, what happens if they get it wrong again? You have to add another line, then another line for if they get it wrong a third time, another for if they get wrong a fourth time... What you'd really need here is a while loop, so that the same bit of code keeps running until a condition (they guess the right number) is fulfilled
๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ bb6
if only i knew how lmao but yeah good idea instead of 100000 console writelines
SinFluxx
SinFluxxโ€ข17mo ago
Iteration statements -for, foreach, do, and while
C# iteration statements (for, foreach, do, and while) repeatedly execute a block of code. You use those statements to create loops or iterate through a collection.
๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ bb6
its my 2nd day learning all this do u think im ready for that yet
SinFluxx
SinFluxxโ€ข17mo ago
๐Ÿ™‚ it's not as bad as it sounds
SinFluxx
SinFluxxโ€ข17mo ago
essentially "while the user still hasn't guessed the number, keep making them guess"
Joe
Joeโ€ข17mo ago
What are you using to learn? Sounds like a lot of your questions are answered in a basic C# beginners course?
Joe
Joeโ€ข17mo ago
C# Fundamentals for Absolute Beginners
Learn C# programming from an expert in the industry. Get the tools, see how to write code, debug features, explore customizations, and more. For newer videos head over toย dot.net/videos
Joe
Joeโ€ข17mo ago
For example
๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ bb6
the hello world thing on microsoft i dont really like videos as they skip over the stuff i need sometimes
Joe
Joeโ€ข17mo ago
Well, most of them cover what you need once you've seen them all, I wouldn't try to run before you can walk. baby steps
SinFluxx
SinFluxxโ€ข17mo ago
Introduction to C# - interactive tutorials
Learn C# in your browser, and get started with your own development environment
๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ bb6
Yeah I think Iโ€™m on that one I havenโ€™t really been following much tho Iโ€™ve been doing my own thing sorta
Joe
Joeโ€ข17mo ago
Stop. Follow the guide, otherwise you will have a lot of questions and not really understand.
Accord
Accordโ€ข17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server