I'm currently having trouble with c#.
I have code that dictates whether someone has entered the right thing or not.
If a user enters a letter instead of a digit, the program sends the screen an error. However, the problem is that the program will continue to go to the next stage of the program, instead of going to the previous stage the user didn't do correctly.
Does anyone have any advice?
Enclose the error checking block inside a while block, with an exit condition that becomes true only when correct input is given.
Giving example using psuedocode:
1)initialize variable check = 1
2)start a while loop which runs as long as check == 1
3)inside the loop:put check = 2
4)inside the loop:get user input
5)inside the loop:check input
6)inside the loop:if input is incorrect, show error message and put check=1, so that the while loop runs again
exit loop
We dont need to do anything when the input is correct as we already assumed it to be correct when we put check = 2.In that case,it will exit the while loop, and proceed to the next steps
Get Answers For Free
Most questions answered within 1 hours.