main.m673 chars24 lines
In the code above, we have set MAX_ATTEMPTS
to 3, which is the maximum of attempts a user can make to input a valid value.
We also initialized numAttempts
to 0 to keep track of the number of attempts the user has made.
In the while
loop, we ask for user input and validate it. If the input is valid, we print out the value and break
out of the loop. If the input is invalid, we print a message and increment numAttempts
by 1.
After the loop, we check if the user exceeded the maximum number of attempts. If they did, we print a message asking them to rerun the program.
gistlibby LogSnag