Learning please help me understand.
I am sure this is so simple for most of you finding this but I am struggling and I really just want to understand it. Help.

22 Replies
What part of this are you having trouble understanding?
I understand what they’re asking me to do I just don’t know how to get there.
I know it has to be a loop
could I use a do-while loop?
For example “do number -1” “while number >= 0”
what would happen in your do-while loop if the user entered 0 as a number?
hmm
It would go negative
So adjust while number > 0 ?
try it and see
lol fail


Arithmetic operators - C# reference
Learn about C# operators that perform multiplication, division, remainder, addition, and subtraction operations with numeric types.
read this
the answer was —number
😎
you dont even need a do while loop there, a simple while loop will suffice such as :
if you want it to count down in real time, you'd want to look at https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.sleep?view=net-9.0 or https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.delay?view=net-9.0 (the second would require you use an async main method, though)
I like that too
That may be too advanced me right now hahah
I think the concept behind that was for me to use a ooop
btw it's better if you use the new api like:
in this way even if user inputs something other than an int , you would be able to gracefully handle that . note that code might need some adjustment but you get the idea
I’m not understanding that
I’m sorry
I’m just learning
what
TryParse
does is that , it tries to parse a string into a number if that string is a valid number e.g "10"
to 10
, however if the string isn't a valid number .eg acd
it would return false but if it's true it would give you the parsed value that's in the above example res
I see
and when would you use that type of statement
when you want to parse a string to a number and you aren't sure if the string is in correct form or not
like in this program, user could type anything on their console , in your
Convert.ToInt32
code, if user inputs abcd
, it would crash your programOhhh I see
Now that makes sense.
$close
If you have no further questions, please use /close to mark the forum thread as answered
Thank you.