Question

In: Computer Science

The Sum and The Average In C++, Write a program that reads in 10 integer numbers....

The Sum and The Average


In C++,

Write a program that reads in 10 integer numbers. Your program should do the following things:

Use a Do statement

Determine the number positive or negative

Count the numbers of positive numbers, and negative

Outputs the sum of:

all the numbers greater than zero

all the numbers less than zero (which will be a negative number or zero)

all the numbers

Calculate the average of all the numbers.


The user enters the ten numbers just once each and the user can enter them in any order. Your program should not ask the user to enter the positive numbers and the negative numbers separately

Solutions

Expert Solution

#include <iostream>
using namespace std;

int main() {
int a[10], i = 0;
int positive = 0, negative = 0, posSum = 0, negSum = 0;

cout << "Enter 10 numbers:\n";
do{
cin >> a[i];
if(a[i] > 0)
{
positive++;
posSum += a[i];
}
else
{
negative++;
negSum += a[i];
}
i++;
}while(i < 10);

cout << "Sum of numbers > 0 = " << posSum << endl;
cout << "Sum of numbers <= 0 = " << negSum << endl;
cout << "Sum of all numbers = " << posSum + negSum << endl;
cout << "Average = " << (posSum + negSum)/10.0;
}


// Hit the thumbs up if you are fine with the answer. Happy Learning!


Related Solutions

Write a program in C++ to read 10 numbers from keyboard and find their sum, average,...
Write a program in C++ to read 10 numbers from keyboard and find their sum, average, maximum and minimum
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
Write a C++ program that reads in a table of numbers and finds out the average...
Write a C++ program that reads in a table of numbers and finds out the average of each row and column. This program should first take two numbers as number of rows and columns as input from the user
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
In c++, write a program that reads a string consisting of a positive integer or a...
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
Write a C program that reads an integer value. Assume it is the number of a...
Write a C program that reads an integer value. Assume it is the number of a month of the year; print out the name of that month (Hint: months need to be captured in an array).
Q#2 Write a C++ program that reads 10 integer values and stores them in an array....
Q#2 Write a C++ program that reads 10 integer values and stores them in an array. The program should find and display the average of the array elements and how many elements are below the average.
Java Write a program that reads 4 integer numbers from the user combine it into a...
Java Write a program that reads 4 integer numbers from the user combine it into a single number. You need to ask the user to first specify how to combine the numbers (forward or backward). Note that for the backward option you need to check that the last digits should be 0, also for the forward option you need to check that the fist digit is not 0. Use for loops and switch for the menu.                       4. Write an application...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT