Why is my program showing my else statement when the response is valid?
Hello, I'm currently in a college course for C# and I'm learning loops right now. I'm doing an assignment where I'm keeping a running sum of a value and then stopping the program once the sum reaches the intended value. The program is supposed to look like the 2nd picture. My professor also attached pseudocode for use to use as a format (3nd picture).
However, if I input a valid number twice, it doesn't give me the error message the first time but gives it on the second number even if they're the same number. What am I missing that could be causing this?
98 Replies
I'd use the debugger to see what the values are and when, and where the code goes at which point
how can i see that in visual studio?
$debug
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
I do see the issue tho
the code could also be cleaned up to not have to do that whole temp reading twice
i tried it without the temp reading line twice, but then i got results like this when i put in a number
well I didn't say you could just remove it 🙂
Protip: a
do..while
loop would be useful^
lol
while
runs 0 or more times.
do...while
runs 1 or more times
the difference is sometimes important, like hereoh ok so i put the validTemp = line in the do {} part and then put the same while{} statement after it