76 309
Assignments Done
Successfully Done
In May 2019

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.
Expert's answer

#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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions