9. Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered.


#include<iostream>
using namespace std;

int main()
{
    int num, cpos=0, cneg=0, czero=0;
    char opt;
    do{
    cout<<"Enter any num";
    cin>>num;
    if(num==0)
        czero++;
    else if(num<0)
        cneg++;
    else
        cpos++;


    cout<<"Do you want to continue Y/N ";
    cin>>opt;
    }while(opt=='Y'|| opt=='y');

    cout<<"Positive = "<<cpos<<endl;
    cout<<"Negative = "<<cneg<<endl;
    cout<<"Zero     = "<<czero<<endl;


}

or

#include<iostream>
using namespace std;

int main()
{
    int num, cpos=0, cneg=0, czero=0;
    char opt;
    while(true){
    cout<<"Enter any num";
    cin>>num;
    if(num==0)
        czero++;
    else if(num<0)
        cneg++;
    else
        cpos++;


    cout<<"Do you want to continue Y/N ";
    cin>>opt;
    if(opt=='N'|| opt=='n')
        break;
    }

    cout<<"Positive = "<<cpos<<endl;
    cout<<"Negative = "<<cneg<<endl;
    cout<<"Zero     = "<<czero<<endl;


}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s