Answer to Question #13779 in C++ for shalennee

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.
1
Expert's answer
2012-08-30T09:10:36-0400
#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;
}

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

Assignment Expert
26.06.14, 17:51

Dear 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.

angelique
10.05.14, 16:10

i 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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS