. Write a C++ program that reads an unspecified number of integers, determines h
ID: 3528710 • Letter: #
Question
. Write a C++ program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values(not counting zeros). Your program ends with the input 0. Display the average as a double. Here is a sample run: Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is 3. The number of negatives is 1. The total is 5. The average is 1.25. please send me the correct code . i saw that some body already wrote the code but it is wrong plz send me the correct codeExplanation / Answer
#include <iostream>
using namespace std;
int main()
{
int num,positive=0,negative=0,total=0,sum=0;
double avg;
cout << " Enter an integer, the input ends if it is 0: " << endl;
do{
cin>>num;
if(num!=0)
{
total=total+1;
if(num>0)
{
positive=positive+1;
}
else
{
negative=negative+1;
}
sum=sum+num;
}
}
while(num!=0);
avg=(double)sum/total;
cout<<" The number of positive is :"<<positive;
cout<<" The number of negative is :"<<negative;
cout<<" Total is :"<<total+1;
cout<<" The average is :"<<avg;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.