English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

ok, so I'm writing a program in which the user inputs a number 0-100 and it outputs a grade any other number comes out as an invalid entry. I did this using an IF statement and put inside a while statement. The number that is supposed to kick it out of the while and end the program is -1 but when I put it -1 in, it outputs -1 as an invalid number and the it kicks out, How can I make it so it doesn't output the -1? my last statement on the IF is else cout << blah blah blah

2007-10-16 07:23:04 · 2 answers · asked by Pep 1 in Computers & Internet Programming & Design

2 answers

There are different ways of doing this, but without seeing how your code is structured, one of the simplest would be to use another if() statement to check if the invalid entry is -1, before printing the error message:

if (number is invalid) {
if (number is not equal to -1) {
print invalid entry message
}
}

2007-10-16 08:39:38 · answer #1 · answered by Anonymous · 0 0

First of all your loop should be a do while because you want the input to be given at least once and then exit on -1

Then in the loop you have to cater for all of the values to produce the grades and -1 to skip this processing.

2007-10-16 15:45:52 · answer #2 · answered by AnalProgrammer 7 · 0 0

fedest.com, questions and answers