Function problem

My program is supposed to take numbers from the user and should only stop when 0 is entered. My should then determine the amount of even and odd numbers entered.
My program continually accepts numbers and doesnt stop. The number 0 does not have an effect on it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
using namespace std;

bool IsOdd(int num);
bool IsEven(int num);

int main()

{
int NumOdds=0;
int NumEvens=0;
int num;


cout<<"Please enter an integer followed by enter. Enter 0 when youre finished"<<endl;
cin>>num;


while (!(num=0))
 {

        if (IsOdd(num))
                NumOdds++;

        if (IsEven(num))
                NumEvens++;

 }

cout<<"Number of Even Numbers:"<<NumOdds<<endl;
cout<<"Number of Odd Numbers:"<<NumEvens<<endl;

return 0;

}


bool IsOdd(int num)
{
if (num % 2 == 0)
return false;
return true;
}

bool IsEven(int num)
{
return (!IsOdd(num));
}

while (!(num=0)) should be while ( !(num==0) ) or while ( num != 0 ) or while ( num )

You should also move line 16 inside th while block, the two ifs can be written as a single if-else
Topic archived. No new replies allowed.