Question #317877

Continuously ask for floating point values (decimal numbers) using the do…while() loop, sum them all up, and store the total into one variable.



The loop shall only terminate for the following reasons:



A negative decimal number is inputted (but still included in the total sum)



The total sum reaches 100.0 or more

Expert's answer



#include <iostream>


using namespace std;


int main()
{
	
	float number;
	float sum=0;
    do{
		cout<<"Enter a number: ";
		cin>>number;
		sum+=number;
	}while(sum<100 && number>0);
    
	cout<<"Sum = "<<sum<<"\n\n";


	system("pause");
	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!

LATEST TUTORIALS
APPROVED BY CLIENTS