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
#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;
}
Comments
Leave a comment