Answer to Question #164196 in C++ for Ahsaam

Question #164196

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.  


1
Expert's answer
2021-02-16T17:23:35-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment