Answer to Question #13777 in C++ for shalennee

Question #13777
(counting positive and negative numbers and computing the average of numbers) 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.
1
Expert's answer
2012-08-30T09:11:04-0400

#include "iostream.h"

void main(){
int q=1, p=0, n=0;
float a=0;
while (q!=0){
& cout<<"enter an integer or 0 to stop: ";
& cin>>q;
& if (q!=0){
& if (q<0) n++;
& else p++;
& a+=q;
& }
}
cout<<"positive numbers: "<<p<<"\n";
cout<<"negative numbers: "<<n<<"\n";
cout<<"average: "<<a/(n+p)<<"\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS