Question: Write a C++ program to read five whole numbers (integers) and perform the following: (1) Display the largest and smallest of the numbers (2) Display

Write a C++ program to read five whole numbers (integers) and perform the following: (1) Display the largest and smallest of the numbers (2) Display the average of the numbers (3) Display sum of the negative numbers (4) Display sum of positive numbers (5) Display how many numbers are even and how many are odd

This is what I have so far, my issue is 1st off I cannot figure out how to incorporate step 5 into the other 4 and whenever I run the program the 1st number inputted is not calculated towards to sums or the average and I cannot figure out why.

For example if I put in, -2,1,2,3,4. It tells me the lowest is -2 and highest is 4 but when it adds the negative and positive it will give negative sum as 0 and positive as 10, and the avg does not calculate correctly because -2 is not included in the calculation.

#include using namespace std; int main() { int min = 0, max = 0, num = 0, counter = 1, pos = 0, neg = 0; double total = 0; cout << "Enter a number: "; cin >> num; max = num; min = num; do { cout << "Enter a number: "; cin >> num; if (num > max) max = num; if (num < min) min = num; if(num < 0) { neg += num; } if(num > 0) { pos += num; } total += num; counter++; } while (counter <= 4); total /= counter; cout << "Smallest Number is: " << min << endl; cout << "Largest Number is: " << max << endl; cout << "Sum of the negative numbers is: " << neg << endl; cout << "Sum of the positive numbers is: " << pos << endl; cout << "Average of numbers is: " << total << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!