1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
DanielleElmas [232]
3 years ago
11

Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative intege

rs as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is 15 20 0 5 -1, the output is:
Computers and Technology
1 answer:
olga55 [171]3 years ago
6 0

Answer:

I am writing the code in C++. Let me know if your want the program in some other programming language.

#include <iostream> // used to invoke input output functions

using namespace std; // used to identify objects like cout cin etc

int main() //start of the main function of the program

{  int number; // integer type variable storing numbers

  cin>>number; // reads numbers that user inputs

       int count = 0; // counts the total numbers entered

       int maximum = 0; // stores maximum number

       int sum = 0; // stores the total sum of numbers

       int average;  // stores average of the numbers

while (number >= 0) // loop checks if the number enters is greater than 0

   {count++; // increments value of count by 1

     sum = sum+number; // stores addition of each number with total

     maximum =  std::max(maximum, number);

// function to find the maximum of the input numbers

     cin>>number;  // keeps reading the entered numbers    }

  if (count == 0) // if value of count is 0

     { average = 0; } // value of average is 0

  else

    {average = sum/count;} // formula to calculate average

      cout<<average; // displays average of numbers

      cout<<" "; //space between average and maximum numbers

      cout<<maximum; } // displays maximum number

Explanation:

The while loop checks the condition that if the integer type number entered by the users are greater than 0. This means it checks that the numbers should be non- negative.

If the while condition is true then the program control enters the body of the loop.

In the first iteration the value of count is incremented by 1. The current value of count was 0 which now becomes 1. The sum variable stores the sum of the entered number and value in sum variable. The current value of sum is 0. This will be added to the value of number. Next the max function is used to find the maximum of the input numbers. It finds the maximum value between each input number and the current value of maximum. cin will keep reading input numbers as entered by the user and stores it in number variable.

The loop will break once the user enters a negative number.

Now the if condition checks if the value of count is equal to 0. This means it checks if there is no number entered. If its true then the value of average will be 0 and if it is false then the average is calculated by dividing the total sum of input numbers (stored in sum variable) with the total numbers entered by user (stores in count variable)

Lastly the values of maximum and average variables are displayed in the output.

You might be interested in
I’f your parents are divorced or separated , which one should complete the parent portion of the profile ? APEX ASAP
vampirchik [111]

Answer:

Your guardian.

Explanation:

Currently who is your guardian either father or mother, he/she will complete the parents portion.

8 0
4 years ago
Read 2 more answers
with your basic knowledge in basic embroidery stitches, how will you motivate your family members the importance of learning bas
LekaFEV [45]
What are embroidery stitches?
4 0
3 years ago
Recursion does NOT take place if any of the following happen:
Kruka [31]

Recursion does NOT take place if any of method A calls method B, which calls method A

II. method A calls method B, which calls method A

<u>Explanation:</u>

Recursion is function is function which is used to call a same function by itself by multiple times with certain condition or loops.

These type of function extremely used on data structure or virus (TSR). Purpose of the function is repeated process and checks the validation and exit by true or false.

In programming languages such as c or c++, vb.net, c# is used to menu organizations so the same function is called and used so the end user don’t write separate function for each times. In case end user has not doesn’t proper exit method on recursion function system either hang or real task to exits.

3 0
3 years ago
Which of the following is part of the process of publishing a website?
aksik [14]
The answer is b. printing a copy of all website pages
3 0
2 years ago
Read 2 more answers
The system where the unit of measurement is centimeter
aleksklad [387]

Answer:

International System of Units

Explanation:

3 0
3 years ago
Other questions:
  • Corey set up his presentation for delivery to his team. The information he had to convey was critical to their job performance.
    6·3 answers
  • Which is the correct formula to add the values in cells A1 and B1?
    11·2 answers
  • True false) keybord has two shift keys.​
    15·1 answer
  • What company uses the most storage?
    15·1 answer
  • Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scor
    5·1 answer
  • Which of the following is the last step in creating a budget?
    13·1 answer
  • If you need to modify a features in a part created using the Mirror tool, you can make the change in the original feature and th
    14·1 answer
  • WILL MARK BRAIN LIST!
    9·2 answers
  • It's so eazy
    12·2 answers
  • Networks that are designed to connect similar computers that share data and software with each other are called:_______
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!