[prog] validate input

olearyck at slu.edu olearyck at slu.edu
Sun Dec 21 21:13:09 EST 2003


On Sunday 21 December 2003 07:23 pm, wolf wrote:
> Hi, I have this C ++ code that basically adds up out of 10 students who
> passed and who did not. You enter 1 if the student passed
> and 2 if the student failed.  It loops around so you can enter your
> answer 10 times. All fine and good : ) However, how
> would I have it check if the user correctly entered a 1 or a 2 and if
> they did not tell them "Invalid Entry Try Again".  The code
> as is, does seem to work correctly : )

right now, your structure is 
if(input==1)
	do something
else
	do something else

What you want structurally is something like
if(input==1)
	do something
else if(input==0)
	do something
else
	input is invalid, do whatever with invalid input

Hope this hint helps.
Christine



More information about the Programming mailing list