Trying to a write code that will Count Positive and Negative numbers and computing the average of nu

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am a student trying to write a program that the use can input as many positive and/or negative numbers and the loop will terminate if the user enters a 0 Then it will sum up the Positives than the negatives and comput the average. This is
what I have so far I get it to start and then after the first entry it just sits there.

Thanks,
#include <iostream><br/>
#include <iomanip><br/>
#include <string><br/>
using namespace std;
int main()<br/>
{<br/>
int number;<br/>
int totalPositive = 0;<br/>
int totalNegative = 0;<br/>
int sum;<br/>
double average;
//Read the Data<br/>
cout << " Enter in a Number (The Program exits if Input is 0) : n ";<br/>
cin >> number;
while (number != 0)<br/>
if (number > 0)<br/>
{<br/>
totalPositive += number;<br/>
}<br/>
else<br/>
{<br/>
totalNegative += number;<br/>
}<br/>
sum += number;<br/>
number++;<br/>
cout << " Enter in a Number (The Program exits if Input is 0) : n ";<br/>
cin >> number;<br/>
<br/>
cout << " The Number of Positives is : " << totalPositive << endl;<br/>
cout << " The Number of Negatives is : " << totalNegative << endl;<br/>
cout << endl;<br/>
<br/>
<br/>
cout << " The Total of Positives and Negatives is : " << sum << endl;<br/>
cout << endl;<br/>
average = sum / (double)number;<br/>
cout << " The Average is : " << average << endl;<br/>
cout << endl;
system("pause");<br/>
return 0;
}

View the full article
 
Back
Top