4. Negative Fusion As I've said before, there are three types of numbers; the positive, the zero, and the negative ones. Today, we shall pay attention only to the negative ones now. Make a loop that will accept random decimal/float numbers. When the user inputs 0, the loop will terminate and then output the sum of all negative numbers inputted in 3 decimal places. Let's code this. Input Multiple lines containing a decimal. 2. 4434 -1.3433 -2.444 6.432 Output A line containing a decimal with three decimal places. -3.787
1
Expert's answer
2021-10-22T07:39:42-0400
#include <iostream>
using namespace std;
int main() {
bool flag = true;
float neg = 0;
while (flag) {
float x;
cin >> x;
if (x == 0.0) flag = false;
else if (x <= 0) neg += x;
}
cout << neg << endl;
return 0;
}
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment