C
C#12mo ago
bb6

❔ 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
bb6
bb612mo ago
yes
SinFluxx
SinFluxx12mo ago
I'm not sure what you're asking, where is it you're wanting the 1-1000 range to come into play?
bb6
bb612mo ago
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
SinFluxx12mo 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
bb612mo ago
ahhhh thank you ive done it now i just need to do one more thing and ive made my first working thing
SinFluxx
SinFluxx12mo 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
bb612mo ago
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
SinFluxx12mo ago
Do you mean add another line for when they get it wrong and need to guess again?
bb6
bb612mo ago
yeah
MODiX
MODiX12mo 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
SinFluxx12mo 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
bb612mo ago
if only i knew how lmao but yeah good idea instead of 100000 console writelines
SinFluxx
SinFluxx12mo 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
bb612mo ago
its my 2nd day learning all this do u think im ready for that yet
SinFluxx
SinFluxx12mo ago
🙂 it's not as bad as it sounds
bb6
bb612mo ago
oh god it has the {}
SinFluxx
SinFluxx12mo ago
essentially "while the user still hasn't guessed the number, keep making them guess"
Joe
Joe12mo ago
What are you using to learn? Sounds like a lot of your questions are answered in a basic C# beginners course?
Joe
Joe12mo 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
Joe12mo ago
For example
bb6
bb612mo ago
the hello world thing on microsoft i dont really like videos as they skip over the stuff i need sometimes
Joe
Joe12mo 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
bb6
bb612mo ago
okay thank you guys
SinFluxx
SinFluxx12mo ago
Introduction to C# - interactive tutorials
Learn C# in your browser, and get started with your own development environment
bb6
bb612mo ago
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
Joe12mo ago
Stop. Follow the guide, otherwise you will have a lot of questions and not really understand.
bb6
bb612mo ago
yeah
Accord
Accord12mo 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
More Posts
❔ Xamarin.Forms Android App problem using Application.Context.StartActivity(intent)Hi, in short, I created a super small Xamarin.Forms Android App. All I need is just to press a butto❔ How can I test a custom IValueResolver in AutoMapper 12?With the latest release of AutoMapper,the public constructor in the ResolutionContext class has been✅ hey am a student and i need to pass exams without learning anybody helphey am a student and i need to pass exams without learning anybody helpReal-time audio recording and streamingHey, so I'm trying to make a home assistant like console app, but I'm having issues with the voice rAdd app created with ng new to solutionHi, is there a way to include an app created with `ng new` to the solution? My goal is start that ❔ Can anyone explain this piece of codeSo I found a piece of code online that solves my problem, but I have to understand how it works befo❔ @Html.DropDownListFor results in null for selected itemHi for the following command: @Html.DropDownListFor(m=>m.Name, new SelectList(Model.Names)) I get❔ WebApplicationFactory and integration testsI've run into an issue with my integration tests and I'm looking for some insight. I'm using `WebApp✅ ✅ C# HttpClient returning 400, but other tools return 200I am trying to make a simple web request to a URL using .NET/C# HttpClient. I am getting a 400 error❔ ASP.NET Core WebAPI - Cannot choose the AuthenticationScheme for MicrosoftGraphs?So I am using the Microsoft.Identity.Web Package to get the access token for a user. This works perf