Answer to Question #317877 in C++ for Three

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

1
Expert's answer
2022-03-25T04:37:10-0400


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

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog