Question No. 01
Write a program that input numbers from the user until user press “E”. Program should display total number of positive and negative numbers entered.
#include <iostream>
using namespace std;
int main() {
int input, neg = 0, pos = 0, zer = 0;
char z;
do {
cout << "Input another positive/negative number or 'E' to stop\n";
cin >> input;
cin.ignore();
if (input > 0){
pos++;
} else if (input == 0){
zer++;
} else if(input < 0){
neg++;
}
} while (z!='E');
cout << "You entered " << pos << " positive numbers.\n";
cout << "You entered " << neg << " negative numbers.\n";
cout << "You entered " << zer << "Zeros.";
return 0;
}
Comments
Leave a comment