Answer to Question #280209 in C for Secret

Question #280209

. Negative Decimal Tally by CodeChum Admin


We've been giving positive numbers too much attention lately, it's time to let negative numbers take the spotlight this time!


Instructions:


Input four float numbers; they could be positive or negative.


Only add all inputted negative numbers, and print its sum, up to 2 decimal place.


Hint: The previous/latest topic is about if-else-elseif statements, but do we need one here?


Instructions

Input four decimal numbers, they could be positive or negative.

Add all the negative numbers, and print the sum, up to 2 decimal places.


Input

A line containing four decimals/floats separated by a space.


-30.22·10.5·-2.2·-1.8


Output

A line containing a negative decimal/floats with two decimal places.


-34.22


1
Expert's answer
2021-12-16T04:47:38-0500
#include <bits/stdc++.h>
using namespace std;


int main()
{
    float num, sum = 0.0;
    
    for (int i = 0; i<4; i++)
    {
        cout<<"Enter the Decimal Number: ";
        cin>>num;
        
        if (num < 0)
        {
            sum += num;
        }
        else
        {
            sum += 0;
        } 
    }
    


    cout<<"Total Sum is: "<<sum<<endl;
    
    
}

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
APPROVED BY CLIENTS