Question
C++ programming For Below: 10 . Modify your program from Programming Project 9 (listed down below and with the correct code) so that it outputs
C++ programming For Below:
10. Modify your program from Programming Project 9 (listed down below and with the correct code) so that it outputs the sum of all positive numbers, the average of all positive numbers, the sum of all nonpositive numbers, the average of all nonpositive numbers, the sum of all positive and nonpositive numbers, and the average of all num-bers entered.
Additional Requirements (from class):
-Note: we must make sure that division by zero won't occur.
(Below is the previous question to give better context to the one above and also the correct code for it which needs to be modified for the above listed question)
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 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.
Code to be Modified:
#include
int main () {
int number, negative_sum=0, positive_sum=0, sum=0, average_neg=0, average_pos=0, average=0; int count=0, positiveCount=0, negativeCount=0; cout << "Please Input 10 whole numbers(Each number should be separated by space or Enter) ";
for(int i=0;i<10;i++) {
//cout<<"i is"<> number;
if (number >= 0 ) { positive_sum += number; positiveCount++; count++; }
else { negative_sum += number ; negativeCount++; count++; } } if(positiveCount>0) { average_pos = positive_sum / positiveCount; }
if(negativeCount>0) { average_neg = negative_sum / negativeCount; }
sum = positive_sum + negative_sum;
if(count>0) { average = sum / count; }
cout< cout << "The Total sum of Negative Numbers is " << negative_sum << " and the average of The negative numbers entered is "; cout << average_neg << endl; cout << "The Total sum of numbers entered is " << sum << " and its average is "<< average << endl; ("PAUSE"); return 0; } All I need is the code for question 10 (the first question). Thanks a bunch :]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started