by CodeChum Admin
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!
Input
A line containing four numbers (may contain decimal places) separated by a space.
2·-4·3.6·1
Output
A line containing the total number of positive integers.
3
#include <iostream>
using namespace std;
int main(){
const int four = 4;
double array[four];
int countOfPositive=0;
cout << "Enter four numbers separated by a space: "<<endl;
for (int i = 0; i < four; i++)
{
cin >> array[i];
}
for (int i = 0; i < four; i++)
{
if (array[i] >= 0) {
countOfPositive += 1;
}
}
cout << "\nTotal number of positive numbers: " << countOfPositive << endl;
return 0;
}
Comments
Leave a comment