27.3k views
2 votes
I need a C++ program to ask the user to put in different numbers until zero is pressed then the program counts the numbers that are put in and finds the sum of the numbers and the negative numbers.

1 Answer

1 vote

Answer:

#include <iostream>

using namespace std;

int main()

{

int input = 0;

int count = 0;

int sum = 0;

int sumNegative = 0;

while (true) {

cout << "Enter a number: ";

cin >> input;

if (input == 0) break;

count++;

sum += input;

if (input < 0) {

sumNegative += input;

}

}

cout << "Count of the numbers: " << count << endl;

cout << "Sum of all the numbers: " << sum << endl;

cout << "Sum of the negative numbers: " << sumNegative << endl;

}

Step-by-step explanation:

Your requirements regarding the sum and the negative numbers was a bit vague so I just did something you can probably adjust easily to your liking.

User Piterio
by
6.0k points