C
C#3w ago
AyaMaya

user input, completes given function

Hello im back :) I am using c# in visual studio. I would like to have a question pop up in the terminal, which day of the advent of code they would like to see, currently on day 2 obviously... if the user gives a value not 1 or 2, i give an error message and ask again. i have never dont getinput in c# so pls help me out with this. I also dont know how to execute a given method without 25 different if statements, im sure there is a better way
4 Replies
Angius
Angius3w ago
Well, to get input from user, you would use Console.ReadLine() To keep repeating that question if the value is invalid, a while or do..while loop will be useful
AyaMaya
AyaMayaOP3w ago
what about the 25 if statements alternative
Angius
Angius3w ago
Depends what they would be doing tbh You could use a switch Switch statement or switch expression, depends
AyaMaya
AyaMayaOP3w ago
it would be saving memory for a string[] of the puzzle input, and then call a function, and output the result switch works perfectly, thanks
Want results from more Discord servers?
Add your server