This program is suppose to :
Prompt the user to enter any number of integers. Keep prompting the user to input integers until the input is 0, which is the signal to stop entering numbers. After the inputs are finished, print out the following information: how many positive numbers were entered, how many negative numbers were entered, the sum of the numbers entered, and the decimal average of the numbers entered.
Sample run: (user input underlined)
Input integer (0 to stop) 12
Input integer (0 to stop) 4
Input integer (0 to stop) -1
Input integer (0 to stop) -5
Input integer (0 to stop) 18
Input integer (0 to stop) 0
# of positives = 3
# of negatives = 2
Total = 28
Average = 5.6
[code]
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main ()
{
int integer;
int positives = 1;
int negatives = 1;
int total = 0;
double average = 0;
cout << "Input integer (0 to stop): " ;
cin >> integer;
while ( integer != 0)
{
total = total + integer;
average = ;// how would i compute the average?
cout << "Input integer (0 to stop): " ;
cin >> integer;
}
if ( integer >= 1)
positives += 1;
cout << " # of positives = " << positives << endl;
if (integer < 1)
negatives += 1
cout << " # of negatives = "<< negatives << endl;
cout << "total = " << total << endl;
cout << "average = " << average << endl;
return 0;
}