Telling if a number is even or odd

Hi guys and garls, why this code is wrong?

The output when an odd number is: "#" is an even odd number. But why...? Then when I try an even number it displays it correct. Thanks :)

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
#include <iostream>
using namespace std;

bool isEven(int);

int main()
{
	int val;

	cout << "Tell me a number and I'll tell you if it's even or odd: ";
	cin >> val;

	if (isEven(val))

	cout << val << " is an even number.";
	
	else
		cout << "\n\n" <<val << " is an even odd.";

	return 0;
}


bool isEven(int number)
{
	bool status;

	if (number % 2 == 0)
		status = true;
	else
		status = false;
	return status;

}
how about you change your cout?
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
#include <iostream>
using namespace std;

bool isEven(int);

int main()
{
	int val;

	cout << "Tell me a number and I'll tell you if it's even or odd: ";
	cin >> val;

	if (isEven(val))

	cout << val << " is an even number.";
	
	else
		cout << "\n\n" <<val << " is an odd.";//see it was so simple

	return 0;
}


bool isEven(int number)
{
	bool status;

	if (number % 2 == 0)
		status = true;
	else
		status = false;
	return status;

PS: did I just answered a question without using my brain??? :D :D :D
Topic archived. No new replies allowed.