Miscellaneous > Programming & Networking
Why does is it return Zero?
(1/1)
Bazoukas:
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 ...
Bazoukas:
Never mind I got the sucker working :D
voidmain:
Never minding...
[ October 24, 2002: Message edited by: void main ]
Bazoukas:
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;
}
Navigation
[0] Message Index
Go to full version