write a program to enter the numbers till the user wants & at the end it should display the count of +ve,-ve & zeroentered | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

write a program to enter the numbers till the user wants & at the end it should display the count of +ve,-ve & zeroentered

22nd Sep 2016, 2:24 AM
Meena
Meena - avatar
2 Answers
+ 4
#include <iostream> using namespace std ; int main () { int num, positive=0, zero=0, negative=0 ; char another ; do { cout << "enter a number " ; cin >> num ; if (num>0) positive++ ; else if (num==0) zero++ ; else if (num<0) negative++ ; cout << "No. of +ve no.s= " << positive << endl ; cout << "No. of zeros= " << zero << endl ; cout << "No. of -ve no.s= " << negative << endl ; cout << "Do you want to enter another number y/n " ; cin >> another ; } while (another=='y') ; return 0 ; }
1st Feb 2018, 12:49 PM
Mukta Malakar
Mukta Malakar - avatar
+ 1
#include <iostream> using namespace std; int main () { int num; int positive=0,negative=0,zero=0; while(1) { cin>>num; if (num>0) positive++; else if (num <0) negative++; else if (num==0) zero++; else break; } cout<<"+ve numbers = "<< positive <<endl; cout<<"-ve numbers = "<< negative <<endl; cout<<"number of zeros = "<< zero <<endl; return 0; }
26th Sep 2016, 2:17 PM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar