I always want to look at the positive side of things, so I decide to seriously look at positive numbers, too!
Will you code along with me?
Instructions:
Input
1. A series of integers
Output
The first multiple lines will contain message prompts to input the integers.
The last line contains the total of all positive integers inputted.
radio_button_unchecked
Test Case 1
expand_less
No Output
Enter n: 2
Enter n: 3
Enter n: 4
Enter n: -1
Enter n: -5
Enter n: 1
Enter n: 0
Total of all positives = 10
radio_button_unchecked
Test Case 2
expand_less
No Output
Enter n: 5
Enter n: 5
Enter n: 5
Enter n: 5
Enter n: 5
Enter n: 0
Total of all positives = 25
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,sum = 0;
do{
cout<<"Enter a Number: ";
cin>>n;
if(n > 0)
{
sum += n;
}
}
while (n != 0);
cout<<"Total of all positives: "<<sum;
}
Comments
Leave a comment