22 Replies
I’m trying to figure out how to get it to re ask to enter the student test score instead it just says the error message but carries on with the rest of the program
One way is recursion, extract the method to an actual function and check the return value.
Okay i will have to look that up
Still very new to all of this
Is there any simpler ways? Just changing the way it’s looped?
what is the valid testScore?
Just anything from 0-100
so loop until you get a valid testScore?
If they enter anything under 0 or 100 it re asks them to enter test score. But if they enter letters or whatever it just carries on with the rest of the code but still displays the error
Yes
you may want to change the
while
condition to check when a) it gets succesfully parsed as a double b) it's between 0-100. You could use a boolean for thisSo instead of using a string I could use a Boolean?
Bool Validinput = false. And put !validInput in the while?
exactly, and the only way
validInput
becomes true, is when the TryParse
is successful + the result is between 0-100Yep it kind of worked
kind of?
double.TryParse
returns a boolean to indicate whether it was a successful
so you take that result + the check for 0-100 and combine them
to determine if it was a valid inputSo where would I put the Validinput?
pseudo code
you can take 2 booleans, one for conversion and one for range, and check if both are true -> assign
validInput = true
or
Ohh okay that’s making more sense
assuming here that 0 and 100 are both invalid
You can do 0 or 100 but that doesn’t matter
you can refactor the code
Yeah
Okay I’ll give that one a shot
Thankyou I appreciate the help