โ 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
yes
I'm not sure what you're asking, where is it you're wanting the 1-1000 range to come into play?
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
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 4ahhhh
thank you ive done it
now i just need to do one more thing and ive made my first working thing
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
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
Do you mean add another line for when they get it wrong and need to guess again?
yeah
wewewwueirie
REPL Result: Success
Console Output
Compile: 528.385ms | Execution: 81.561ms | React with โ to remove this embed.
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 fulfilledif only i knew how lmao
but yeah good idea instead of 100000 console writelines
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.
its my 2nd day learning all this do u think im ready for that yet
๐ it's not as bad as it sounds
oh god it has the {}
essentially "while the user still hasn't guessed the number, keep making them guess"
What are you using to learn?
Sounds like a lot of your questions are answered in a basic C# beginners course?
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
For example
the hello world thing on microsoft
i dont really like videos as they skip over the stuff i need sometimes
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
okay
thank you guys
I believe this is the non-video version:
https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/tutorials/
Introduction to C# - interactive tutorials
Learn C# in your browser, and get started with your own development environment
Yeah I think Iโm on that one
I havenโt really been following much tho Iโve been doing my own thing sorta
Stop. Follow the guide, otherwise you will have a lot of questions and not really understand.
yeah
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.