Assignments » Flow Of Control » Set2 » Solution 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 n, sum_p=0, sum_n=0, sum_z=0;
	char choice;

	do
	{
		cout<<"Enter number ";
		cin>>n;

		if(n>0)
			sum_p++;
		else if(n<0)
			sum_n++;
		else
			sum_z++;

		cout<<"Do you want to Continue(y/n)? ";
		cin>>choice;

	}while(choice=='y' || choice=='Y');


	cout<<"Positive Number :"<<sum_p<<"\nNegative Number :"<<sum_n<<"\nZero Number :"<<sum_z;


	return 0;
}

 

 

Enter number : 56
Do you want to Continue(y/n)? y
Enter number : -9
Do you want to Continue(y/n)? y
Enter number : 67
Do you want to Continue(y/n)? y
Enter number : 54
Do you want to Continue(y/n)? y
Enter number : -98
Do you want to Continue(y/n)? y
Enter number : -13
Do you want to Continue(y/n)? y
Enter number : 0
Do you want to Continue(y/n)? y
Enter number : -98
Do you want to Continue(y/n)? y
Enter number : 0
Do you want to Continue(y/n)? n
Positive Number :3
Negative Number :4
Zero Number :2

 

«back