Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago