the problem is: write a program that reads an unspecified number of integers, de
ID: 3620259 • Letter: T
Question
the problem is: write a 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 floating point number. here is a sample run: Enter an int value, the program exits if the input 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.25the problem is: write a 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 floating point number. here is a sample run: Enter an int value, the program exits if the input 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
Explanation / Answer
please rate - thanks #include <iostream>using namespace std;
int main()
{int pluses=0,minuses=0,num,sum=0,n=0;
double average;
cout<<"Enter an int value, the program exits if the input is 0,";
cin>>num;
while(num!=0)
{if(num>0)
pluses++;
else
minuses++;
sum+=num;
n++;
cout<<"Enter an int value, the program exits if the input is 0,";
cin>>num;
}
cout<<"the number of positives is "<<pluses<<endl;
cout<<"the number of negatives is "<<minuses<<endl;
cout<<"the total is "<<sum<<endl;
average=sum/(double)n;
cout<<"the average is "<<average<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.