(Validating User Input) The examination-results program of Fif. 3.12 assumes that any val- ue input by the user that is not a 1 must be a 2. Modify the application to validate its inputs. On any input, if the value entered is other than 1 or 2, keep looping until the user enters a correct value.

What will be an ideal response?


```
// Examination results problem: Validating input.
#include
using namespace std;

int main()
{
// initializing variables in declarations
int passes = 0; // number of passes
int failures = 0; // number of failures
int studentCounter = 1; // student counter
int result; // one exam result (1 = pass, 2 = fail)

// process 10 students using counter-controlled loop
while ( studentCounter <= 10 )
{
// prompt user for input and obtain value from user
cout << "Enter result (1 = pass, 2 = fail): ";
cin >> result; // input result

if ( result == 1 ) // 1 is a valid input
{
passes = passes + 1; // increment passes
studentCounter = studentCounter + 1; // increment studentCounter
} // end if
else if ( result == 2 ) // 2 is a valid input
{
failures = failures + 1; // increment failures
studentCounter = studentCounter + 1; // increment studentCounter
} // end else if
else // invalid input; tell user and prompt again
{
cout << "Invalid input" << endl;
} // end else
} // end while

// termination phase; display number of passes and failures
cout << "Passed " << passes << "\nFailed " << failures << endl;

// determine whether more than eight students passed
if ( passes > 8 )
cout << "Bonus to instructor!" << endl;
} // end main
```

Computer Science & Information Technology

You might also like to view...

Your company has a suite in a business complex. Another company in the suite next to you has a wireless 802.11b network with the SSID Company A. You can pick up that company’s signal from your suite. Your company would like to put up its own wireless network with two access points. Discuss how you would set up these two access points so that your company can obtain optimal performance.

What will be an ideal response?

Computer Science & Information Technology

Windows File Explorer is used to find and organize files and folders

Indicate whether the statement is true or false

Computer Science & Information Technology

The audience's attention should focus primarily on the ____.

A. slides B. media C. presenter D. all of the above

Computer Science & Information Technology

To set column and row titles on the screen while you scroll, which of the following command(s) would you use?

A) Go To B) Insert C) Freeze Panes D) Hide

Computer Science & Information Technology