Monday 14 January 2013

Let Us C Chapter 3 problem No: B-g


//Program to display count of +ve, -ve or zero numbers inserted by users

#include<iostream>
#include<conio.h>
#include<windows.h>

using namespace std;

int main(void)
{
    int n,pos =0, neg =0, zero =0, i = 0;
    char c;


  do
    {
        cout<<"Insert any number:  ";
        cin>>n;

        if(n==0)
        {
            zero++;
        }

        else if(n>0)
        {
            pos++;
        }

        else
        {
            neg++;
        }
        i++;


    cout<<"Do you want to insert a number:  ";
    c=getche();
    cout<<endl;
    }
   while((c=='y') || (c== 'Y'));



    cout<<endl;
    cout<<"You entered total "<<i<<" terms.";
    cout<<endl;
    cout<<"In which, total number of\n";
    cout<<"Positives:  ";
    cout<<pos;
    cout<<endl;
    cout<<"Negatives:  ";
    cout<<neg;
    cout<<endl;
    cout<<"Zeros    :  ";
    cout<<zero;
}

No comments:

Post a Comment

Comments please: