### Having Problem With a Function. Need Assitance

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

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 #include #include 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

 123 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 !