I'm writing a program in C++ that takes integers from the user until they press "x" to stop.
Then the program will print the number of positives, negatives and zeros.
But whenever the user inputs "x", the program goes into an infinite loop.
I tried removing the "ZEROS" part and just made counters for positives and negatives and it worked good. But I want to count the zeros.
I need to let the user enter numbers including 0 until they enter character x.
Here is my code:
#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 'x' to stop\n"; cin >> input; cin.ignore(); if (input > 0){ pos++; } else if (input == 0){ zer++; } else if(input < 0){ neg++; } } while (z!='x'); cout << "You entered " << pos << " positive numbers.\n"; cout << "You entered " << neg << " negative numbers.\n"; cout << "You entered " << zer << "Zeros."; return 0; }
zsupposed to be?