Negative or positive number finder | How many inputs are positives or negative

To get this types of output:

Sample Output:
Enter any Number: 15
Do you want to input again(Y/N): y
Enter any Number: -20
Do you want to input again(Y/N): y
Enter any Number: 40
Do you want to input again(Y/N): y
Enter any Number: 0
Do you want to input again(Y/N): y
Enter any Number: 5
Do you want to input again(Y/N): n

Count of Positive Numbers = 3
Count of Negative Numbers = 1
Count of Zero Numbers = 1

Average = 8

source codes:

# include <iostream>
using namespace std;

void main ()
{
int positive=0;
int negative=0;
int zero=0;
int ans=0;
int i=1;
char test='y';
int avg;
int tans=0;
int counter=0;

while (i>=1)
{
if (test=='y' || test=='Y')
{
cout<<"Please enter number here: ";
cin>>ans;

tans=tans+ans;
counter=counter+1;

if (ans<0)
negative++;
else if (ans>0)
positive++;
else if (ans==0)
zero++;
cout<<"Do you want to input again (Y/N) ";
cin>>test;
}
else
break;
}
avg=tans/counter;
cout<<"All positive inputs:"<<positive<<endl;
cout<<"All negative inputs:"<<negative<<endl;
cout<<"All zero inputs :"<<zero<<endl;
cout<<"Average :"<<avg<<endl;
}


Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System