Author Topic: Why does is it return Zero?  (Read 1209 times)

Bazoukas

  • Member
  • **
  • Posts: 866
  • Kudos: 140
    • http://whitehouse.com
Why does is it return Zero?
« on: 24 October 2002, 21:26 »
The program should see if you entered an even or odd or a zero and tell you how many from each. I havent made the loop yet. I am trying it with one number for now.
  The problem is that it cant count it  :(
==========================================
#include <iostream.h>

int  classifynumber (int number, int zerocount, int oddcount, int evencount);


int main () {

   
    int zerocount;
   zerocount=0;
   
   int oddcount;  
   oddcount=0;
   
   int evencount;
   evencount=0;

   
   
   cout<<"Enter 2 numbers"<<endl;
      int number;
      cin>>number;
   
   
   
   int classifynumber (int number, int zeros, int odds, int evens);

   cout <<"the number you entered "<< number <<" there are evecount: "<< evencount <<" oddcount " <<oddcount <<" zerocount: "<< zerocount<<endl;
   return 0;
   
}

int classifynumber(int number, int zerocount, int oddcount, int evencount)
{
   
   switch(number%2)
   {
      
      
      case 0:
         evencount++;
      if (number==0)
         zerocount++;
      break;
      case 1:
         case -1: oddcount++;
         }
         
return number;
         }
==================================================
output
Enter 2 numbers
3
the number you entered3 there are evecount: 0 oddcount 0 zerocount: 0

----------------------------------------------
Program exited successfully with errcode (0)
Press the Enter key to close this terminal ...
Yeah

Bazoukas

  • Member
  • **
  • Posts: 866
  • Kudos: 140
    • http://whitehouse.com
Why does is it return Zero?
« Reply #1 on: 24 October 2002, 21:49 »
Never mind I got the sucker working   :D
Yeah

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Why does is it return Zero?
« Reply #2 on: 24 October 2002, 21:55 »
Never minding...

[ October 24, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...

Bazoukas

  • Member
  • **
  • Posts: 866
  • Kudos: 140
    • http://whitehouse.com
Why does is it return Zero?
« Reply #3 on: 24 October 2002, 10:05 »
shit voidMan. I feel bad now man  LOL. I feel like a jackass now.
But thanks dude a lot

here is the whole program for whoever is intrested.


//Ex 3.20
#include <iostream.h>
#include <iomanip.h>

const int N=20;

void initialize(int& zerocount, int& oddcount, int& eventcount);
void getnumber(int& num);
void classifynumber (int num, int& zerocount, int& oddcount, int& evencount);

void printresults(int zerocount, int oddcount, int evencount);

int main()

{
   int counter;
   int number;
   
   int zeros;
   int odds;
   int evens;
   
   initialize (zeros, odds, evens);
   
   cout<<"please enter "<<N<<"integers"<<endl;
   cout<<"The numbers you entered are  "<<endl;
   
   for (counter=1; counter<=N; counter++)
   {
      
      getnumber(number);
      
      cout<<setw(3)<<number;
      classifynumber(number, zeros, odds, evens);
      
   }
   
   cout<<endl;
   printresults(zeros, odds, evens);
   return 0;
}

void initialize(int& zerocount, int& oddcount, int& evencount)
{
   
   zerocount=0;
   oddcount=0;
   evencount=0;
}

void getnumber(int& num)
{
   cin>>num;
}

void classifynumber(int num, int& zerocount, int& oddcount, int& evencount)

{
   
   switch(num%2)
   {
      case 0:
         evencount++;
      if (num==0)
         zerocount++;
      break;
      case 1:
         case -1: oddcount++;
         }
         
      }
      
      void printresults(int zerocount, int oddcount, int evencount)
   {
      
      cout<<"There are "<<evencount<< " evens, "<<"which also includes "<< zerocount<<" zeros"<<endl;
      cout<<"Total number of odds are: "<<oddcount<<endl;
      
   }
Yeah