Question

This is for C++ programming: Write a while loop that finds the average of all of...

This is for C++ programming:

Write a while loop that finds the average of all of the whole numbers entered from the user, until a -1 is entered (the -1 should not be included in the calculation of the average.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main() {
    double total = 0, count = 0, num;
    while (true) {
        cout << "Enter a number(-1 to stop): ";
        cin >> num;
        if (num == -1)
            break;
        total += num;
        ++count;
    }
    cout << "Average of entered numbers is " << (total / count) << endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
This is for C++ programming: Write a while loop that finds the average of all of...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Answer using programming in C only. 6 pts Use a while loop to complete the following:...

    Answer using programming in C only. 6 pts Use a while loop to complete the following: Prompt the user to enter integers one by one, until the user enters a negative number to stop Calculate the sum and the average of all the numbers entered by the user Print the sum and the average onto the screen after the loop. Declare and initialize all variables. Be sure to keep a count of the numbers entered for the average calculation

  • (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers...

    (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers entered by the user:  Ask the user to enter an integer number or -1 to stop  Add the entered numbers  Compute the average of the numbers outside the loop after termination  Print the average

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based...

    C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based off of 9). Program Info:   #9. Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once...

  • In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all...

    In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all the seeds of a integer given by the user. Let’s define a seed of an integer, n, to be a positive value that equals n when multiplied by its individual digits. For example, 23 is a seed of 138 because 23 × 2 × 3 = 138. 111 is an example of a seed of itself because 111 × 1 × 1 × 1...

  • What is a "sentinel value"? What is the format for a while loop? What is the...

    What is a "sentinel value"? What is the format for a while loop? What is the format for a do-while loop? .Write some instructions which will read a series of numbers (type double) and add them to a total until the number -1 is entered The - 1 is not added to the total. Write some instructions which will read a series of numbers (type double) and add them to a total until the character control-d is entered. Write a...

  • using while loop

    Sum of Numbers: Write a program that asks the user for a positive integer value.The program should use a loop to get the sum of all the integers from 1 up to the number entered.For Example, if the user enters 50, the loop will find the sum of 1,2,3,4,…50.C++

  • compute x = e^t using while loop in c programming, where t is days from 1...

    compute x = e^t using while loop in c programming, where t is days from 1 to 7 and let the answer be in tabular form with x and t on the first row. x values should be whole numbers.

  • In C programming please (b) You will write a program that will do the following: prompt...

    In C programming please (b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter 'O' You will compule statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character 'Q' Example input mJ0*5/1+x1@3qcxQ The 'Q' should be included when computing the statistics properties of the input....

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT