Having Problem With a Function. Need Assitance

Write your question here.
I'm having a problem with the final function "orderTestAbs". The first 2 work fine. I'm not sure how to use absolute values in it or how to call them. The function is supposed to do this - "This function should perform exactly the same as orderTest,
but instead uses the absolute value of the inputs for comparison.
At the very least, it should be calling your absValue function a few times.
Even better, it should be calling orderTest to do the bulk of the work."
I'd appreciate any help

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  

#include<iostream>
#include<cmath>
using namespace std;

bool orderTest (int, int, int);
int absValue (int);
bool orderTestAbs (int, int, int);

/*Your main function should contain a few calls to all of these functions
to demonstrate that they work correctly.
Be sure that all code paths are exercised by your choice of input values.*/
int main()
{
	//this calls orderTest function
	int x, y, z;
	cout << " Enter three numbers \n";
	cin >> x >> y >> z;
	orderTest(x, y, z);

	//this calls absValue function
	int num;
	cout << " Enter a number  \n";
	cin >> num;
	absValue(num);

	//this calls orderTestAbs function
	int a, b, c;
	cout << " Enter three numbers  \n";
	cin >> a >> b >> c;
	orderTestAbs(a, b, c);

	system("pause");
	return 0;
}



/*orderTest - orderTest is a function that accepts three integer input parameters, x, y, and z.
It tests to see if x <= y and that y <= z. If this is true, the function should output "In order" to
the console and return true. Otherwise, the function should output "Out of order" and return false. */

bool orderTest(int numX, int numY, int numZ)
{
	bool status;

	if (numX <= numY && numY <= numZ)
	{
		cout << " The numbers are in order\n\n";
		status = true;
	}
	else
	{
		cout << " The numbers are out of order\n\n";
		status = false;
	}
	return status;
}




/*absValue - absValue is a function that accepts an integer input and returns an integer that represents
the absolute value of the input. It should produce no output on its own.
Please do the absolute value calculation work directly in the function (use an if/else and some simple math;
do not call built-in math functions to do this). */

int absValue(int value)
{
	if (absValue < 0)
	{
		value = -value;
	}
	else
	{
		value = value;
	}
	cout << " Absolute value of " << value << " is " << abs(value) << endl<< endl;
	return (value);
}



/*orderTestAbs - This function should perform exactly the same as orderTest,
but instead uses the absolute value of the inputs for comparison.
At the very least, it should be calling your absValue function a few times.
Even better, it should be calling orderTest to do the bulk of the work. */

bool orderTestAbs(int numA, int numB, int numC)
{
	bool status;

	if (abs(numA <= numB && numB <= numC))
	{
		cout << " The numbers are in order\n\n";
		status = true;
	}
	else
	{
		cout << " The numbers are out of order\n\n";
		status = false;
	}
	return status;
}


Last edited on
A couple of things.

1. None of your sub-functions should contain cout statements.
Because this just creates a messy display when you try to make one call the other, like say

1
2
3
bool orderTestAbs(int numA, int numB, int numC) {
    return orderTest( absValue(numA), absValue(numB), absValue(numC) );
}
Salem c what do you mean by "sub-function" ? should I rewrite any of the other code ?
Last edited on
Like orderTest is both a sub-function of main, and of orderTestAbs.

The whole purpose of a function is to have a clearly defined purpose.
Do one thing, and do it well.

Doing something, and then printing it out to cout are two things.
- what if I didn't want it printed?
- what if I wanted it printed somewhere else?
Thanks a lot salem c, appreciate it !
Topic archived. No new replies allowed.