Monday, January 9, 2017

Count Positive and Negative Numbers in C++

I this article I would like to share with you a sample program that will ask the user to give a series of positive and negative numbers and then our program will count how many positive and negative numbers being given by our user using array in C++. I wrote this code almost 7 years ago while I am teaching C++ programming in the university that I am working with. I hope you will find my work useful. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>

using namespace std;

main() {

    int grades[5],positive=0,negative=0;

   for (int list=0; list <5; list+=1) {
       cout << "Enter value No " << list+1 << ":";
       cin >> list[grades];
   }
   cout << "\n\n";
   for (int list=0; list <5; list+=1) {

      if (list[grades] >= 0) {
           positive++;
   }
   else {
       negative++;
   }
}
   cout << "\n\n";
   cout << "\nNumber of Positive Number : " << positive;
   cout << "\nNumber of Negative Number : " << negative;
   cout << "\n\n";
       system("PAUSE");
}

No comments:

Post a Comment