Question

In C++ Complete the template Integer Average program. // Calculate the average of several integers. #include...

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
How do I make this code not include negative numbers in the total or average if...
How do I make this code not include negative numbers in the total or average if they are entered? (C++) For example, if you enter 4, 2, and -2, the average should not factor in the -2 and would be equal to 3. I want the code to factor in positive numbers only. ----- #include using namespace std; int main() {    int x, total = 0, count = 0;       cout << "Type in first value ";   ...
The Greatest and the Least of These: Write a program with a loop that lets the...
The Greatest and the Least of These: Write a program with a loop that lets the user enter a series of integers, followed by the end of a sentinel -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered. ATTACHED IS MY CODE 1. I must use a constant in my line of code, WHERE CAN I PUT A CONSTANT? 2. How can i fool...
im trying to make a program that will use a while loop to repeatedly ask a...
im trying to make a program that will use a while loop to repeatedly ask a user for a test score. Use a counter to exit the loop when the user has entered 10 test scores. The loop is to figure out the total of all the scores and the highest score. it must use a while loop please explain problems in code the bottom code is my work done but does not work. #include <iostream> using namespace std; int...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int num2; cout << fixed << showpoint << setprecision(2); cout << "Enter two integers: "; cin >> num1 >> num2; cout << endl; if (num1 != 0 && num2 != 0) cout << sqrt(abs(num1 + num2) + 0.5) << endl; else if (num1 != 0) cout << floor(num1 + 0.5) << endl; else if (num2 != 0) cout << ceil(num2 + 0.5) << endl; else...
C++ Create a program that will use pointers to determine the average (to 1 decimal place)...
C++ Create a program that will use pointers to determine the average (to 1 decimal place) of a series of grades entered into an array. You can assume a maximum of 15 students and the user will end input with a sentinel value. Make sure to use pointer increment and a pointer comparison while loop, and not array notation or array index numbers or offsets. You will use a function called getgrades. Send the array name (a pointer constant) to...
Do While loop on C++ I need to program a do while loop in which the...
Do While loop on C++ I need to program a do while loop in which the user have to choose between option A,a, B,b or C,c. I need a do while loop that if other letter (different from options is choose) the loop print a cout saying "Invalid selection. Plese, enter the selection again.   I have one, but isn't working well int main() { char option; do { cout<<"Please choose one of the following options: "<<endl<<endl; cout<<"Option A - Julian...
Please use this template. In this exercise you are to use a vector to store integers...
Please use this template. In this exercise you are to use a vector to store integers entered by the user. Once you have filled the vector, ask the user for a value to search for. If found, remove the value from the vector, keeping all other values in the same relative order, and then display the remaining values. #include <iostream> #include <vector> #include <climits> using namespace std; //Fills vector with user input until user enters 0 (does not include 0...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT