(Averaging Integers) Write a program that uses a for statement to calculate and print the average of several integers. Assume the last value read is the sentinel 9999. A typical input sequence might be 10 8 11 7 9 9999 indicating that the program should calculate the average of all the values preceding 9999.
What will be an ideal response?
```
// Average a sequence of integers.
#include
using namespace std;
int main()
{
int value; // current value
int count = 0; // number of inputs
int total = 0; // sum of inputs
// prompt for input
cout << "Enter integers (9999 to end):" << endl;
cin >> value;
// loop until sentinel value read from user
while ( value != 9999 )
{
total += value; // update sum
count++; // update number of inputs
cin >> value; // read in next value
} // end while
// if user entered at least one value
if ( count != 0 )
cout << "\nThe average is: "
<< static_cast< double > ( total ) / count << endl;
else
cout << "\nNo values were entered." << endl;
} // end main
```
You might also like to view...
An example of a square root function written correctly is ____.
A. SQRT(C4) B. =SQROOT(C4) C. =SQRT(C4) D. SQROOT(C4)
Sorting enables you to target a mailing to individuals in a specific state or ZIP code area.
Answer the following statement true (T) or false (F)
Embedded styles apply to the Hypertext Markup Language (HTML) documents in which they are created and are accessible to other documents in the website.?
Answer the following statement true (T) or false (F)
Data models are unique to Power Pivot.?
Answer the following statement true (T) or false (F)