Create a C++ program that will accept input of any number then press 0 to stop. Count and display the positive and negative numbers.
#include <iostream>
using namespace std;
int main() {
int num_pos = 0, num_neg = 0, x;
cin >> x;
while (x) {
if ( x > 0)
num_pos++;
else
num_neg++;
cin >> x;
}
cout << "There were " << num_pos << " positive and "
<< num_neg << " negative numbers." << endl;
return 0;
}
Comments
Leave a comment