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

(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
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
Write a C program to show sum of 10 elements of array and show the average....
Write a C program to show sum of 10 elements of array and show the average. [10]
Let a , b , c be three integer numbers. Write a C++ program with a...
Let a , b , c be three integer numbers. Write a C++ program with a functions void rotate1(int* a,int* b,int* c) void rotate2(int& a,int& b,int& c) such that a -> b , b -> c and c -> a. Thus we use two different approaches (pointers in rotate1 and references in rotate2).
In C++, Write a program that accepts exactly ten (10) integer numbers from the user. When...
In C++, Write a program that accepts exactly ten (10) integer numbers from the user. When the user is done inputting these numbers, the program prints back: (i) the sum of the 10 numbers, (ii) the minimum value from the 10 numbers, and (iii) the maximum value from the 10 numbers.
C++ program that reads a positive integer number from a user and displays all binary numbers...
C++ program that reads a positive integer number from a user and displays all binary numbers from 0 to the number. For the program, you can assume that the input number is a number between 0 and 100. Sample Run 1: Assume that the user typed the following number. 5 This is the correct output of your program. 000 001 010 011 100 101 Sample Run 2: Assume that the user typed the following number. 0 This is the correct...
Part 1: Write a program that finds the sum and average of a series of numbers...
Part 1: Write a program that finds the sum and average of a series of numbers entered by the user. The program will first ask the user how many numbers there are. It then prompts the user for each of the numbers in turn and prints out the sum, average, the list of number from the user. Note: the average should always be a float, even if the user inputs are all ints. Part 2: Same as part 1 except...
Write a C/C++ program which reads in a list of process names and integer times from...
Write a C/C++ program which reads in a list of process names and integer times from stdin/cin and simulates round-robin CPU scheduling on the list. The input is a list of lines each consisting of a process name and an integer time, e.g. ProcessA 4 ProcessB 10 Read the list until end of transmission (^d). You should read the list and represent it in a linked list data structure. You should use the alarm system call to schedule a timer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT