Answer to Question #258527 in C++ for yan

Question #258527

There are different kinds of numbers, but among them all, the most commonly used numbers in our daily lives are those positive ones. So, I only want you to count all the positive numbers from the 4 inputted values and print out the result.


Go and search for the positive ones among these four!


1
Expert's answer
2021-10-29T03:59:07-0400
#include <iostream>
using namespace std;

int main() {
    int x, sum=0;

    for (int i=0; i<4; i++) {
        cin >> x;
        if (x > 0) {
            sum += x;
        }
    }

    cout << "The sum of positive number is " << sum << endl;

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