In C++ Complete the template Integer Average program.
// Calculate the average of several integers.
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int value; // current value
int count = 0; // number of inputs
int total; // sum of inputs
// prompt for input
cout << "Enter integers (9999 to end):" << endl;
cin >> value;
total = 0;
// loop until sentinel value read from user
/* Write a while loop to loop while value does not equal 9999 */
{
/* Write a statement to add value to total */
/* Write a statement to increment count */
cin >> value; // read in next value
} // end for
// if user entered at least one value
if ( count != 0 )
cout << "\n The average is: "
<< /* Convert total to a double and divide it by count */ << endl;
else
cout << "\n No values were entered." << endl;
return 0; // indicate program ended successfully
} // end main
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int value; // current value
int count = 0; // number of inputs
int total; // sum of inputs
// prompt for input
cout << "Enter integers (9999 to end):" << endl;
cin >> value;
total = 0;
// loop until sentinel value read from user
/* Write a while loop to loop while value does not equal 9999
*/
while(value!=9999)
{
/* Write a statement to add value to total */
total+=value;
/* Write a statement to increment count */
count++;
cin >> value; // read in next value
} // end for
// if user entered at least one value
if ( count != 0 )
cout << "\n The average is: "
<< ((double)total)/count << endl;
else
cout << "\n No values were entered." << endl;
return 0; // indicate program ended successfully
} // end main
_________________________
Output:
_______________Could you plz rate me well.Thank You
Get Answers For Free
Most questions answered within 1 hours.