Coding help on some integer manipulation

Hey, all. My code works without the functions in it. But then if I take out the if statements about the difference, the functions work again.

It's as if one can't run without the other for some reason.

Attached is my code. Thanks in advance!

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
50
51
52
53
54
55
56
57
58
59
60
61
62
  #include <iostream>
using namespace std;

void numberOneEval(int x) {
	if (x % 2 == 0) {
		cout << x << " is even." << endl;
	}
	else {
		cout << x << " is odd." << endl;
	}
}

void numberTwoEval(int y) {
	if (y % 2 == 0) {
		cout << y << " is even." << endl;
	}
	else {
		cout << y << " is odd." << endl;
	}
}


int main() {
	int number_1, number_2;
	int difference;

	cout << "I will now perform a few operations upon the entrance of two integers provided by you." << endl;
	cout << "Proceed by entering one at a time." << endl;
	cin >> number_1;

	cout << "Okay, great. Now the second integer value." << endl;
	cin >> number_2;

	if (number_1 > number_2) {
		difference = number_1 - number_2;
	}
	if (number_2 > number_1) {
		difference = number_2 - number_1;
	}
	if (number_1 == number_2) {
		difference = number_1 - number_2;
	}

	cout << "The difference between the two is " << difference << "." << endl;

	if (difference % 2 == 0) {
		cout << "The difference is even." << endl;
		return 0;
	}
	if (difference % 2 != 0) {
		cout << "The difference is odd." << endl;
		return 0;
	}

	numberOneEval(difference);
	numberTwoEval(difference);



	return 0;

}
First of all you dont need same code doing same stuff twice.I mean the lines 4 and 13.


And this

Attached is my code. Thanks in advance!


Its you who hav to make the code run and we will assit you in your endeavour.Best of luck!! :)
Can you explain what you're trying to do with your program?
DeathLeap:

Yeah sorry about that! I have to take two numbers, discern between which one is greater than the other, calculate the difference, state if the numbers entered are even or odd and then state whether or not the difference is even or odd.
MaBunny:

I think you're misunderstanding my functions. They're to discern between if number one and number two are even or odd.
I wrote this program for you, try to understand it and if you have any questions ask me please.

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

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

int main() 
{
	int num1 = 0;
	int num2 = 0;
	int difference = 0;
	bool oddOrEvenNum1 = oddOrEven(num1);      //0 = odd, 1 = even
	bool oddOrEvenNum2 = oddOrEven(num2);
	cout << "Instructions: 1 Means Even, 0 Means Odd" << endl;
	cout << "ENTER TWO NUMBERS: ";
	cin >> num1 >> num2;

	difference = num2 - num1;

	if (num1 > num2)
	{
		cout << "First number > Second number" << endl;
	}
	else
	{
		cout << "Second number > First number" << endl;
	}
	cout << "The first number is Even or Odd? " << oddOrEven(num1) << endl;
	cout << "The second number is Even or Odd? " << oddOrEven(num2) << endl;
	cout << "Is the difference " << "(" << difference << ")" << " an Odd Number? " << oddOrEven(difference) << endl;
	system("PAUSE");
	return 0;

}
Last edited on
DeathLeap:

Worked great! Thanks so much!

It makes sense, too which is nice. I appreciate it!
Topic archived. No new replies allowed.