Question #13779

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 floating-point number.

Expert's answer

#include <iostream>

using namespace std;

int main()

{

int number=0,positive=0,negative=0,sum=0;

cout<<"Start entering numbers: ";

while (true)

{

& cin>>number;

& if (number==0)

& {

break;

& }

& if (number>0)

& {

positive++;

& }

& else

& {

negative++;

& }

& sum+=number;

}

cout<<positive<<" positive numbers"<<endl;

cout<<negative<<" negative numbers"<<endl;

cout<<"total: "<<sum<<endl;

cout<<"average: "<<((float)sum)/(positive + negative)<<endl;

return 0;

}

using namespace std;

int main()

{

int number=0,positive=0,negative=0,sum=0;

cout<<"Start entering numbers: ";

while (true)

{

& cin>>number;

& if (number==0)

& {

break;

& }

& if (number>0)

& {

positive++;

& }

& else

& {

negative++;

& }

& sum+=number;

}

cout<<positive<<" positive numbers"<<endl;

cout<<negative<<" negative numbers"<<endl;

cout<<"total: "<<sum<<endl;

cout<<"average: "<<((float)sum)/(positive + negative)<<endl;

return 0;

}

## Comments

Assignment Expert26.06.14, 17:51Dear customer,

Unfortunately, your question requires a lot of work and cannot be done for free.

Please submit it with all requirements as an assignment to our control panel and

we'll assist you.

angelique10.05.14, 16:10i need some one who can try to give me some explanation about this codes

because i want to understand the logic of those codes

## Leave a comment