Need some help making a program using floats and functions
I need to use a function that accepts three floating point values as parameters and sorts them from largest to smallest. The program must use one or more pointers and the function will affect the three variables input in the calling program (main). I can use 3 if statements. Thanks for any help you can provide me. Im new to floats :)
you can use the max() macro to compare each pair:
float biggest = max(bigger, c);
float smallest = (bigger == a?b:a;)
now you have the three number sorted: smallest, bigger and biggest.
Complex way !!! :
I'll point to the smallest with s; bigger with b; biggest with z.
U have 6 metods of arrangments:
1. s b w
2. s w b
3. b s w
4. b w s
5. w s b
6. w b s
use those numerical values as return values from the function;
Assume the three values are a,b and c:
use this: //I'll ignore the equality case.
Note that they are only 3 if statements :
if(a<b&&a<c)if(b<c)return 1;else return 2;
else if(b<a&&b<c)if(a<c)return 3;else return 4;
else if(c<a)return 5;else return 6;
the first: if(..)...else if(..)...else...
the second and the third are : if(..)...else...
Last edited by Amahdy; 10-27-2006 at 11:33 AM.
thanks alot for the code and your time.
float * sort3(float &one, float &two, float &three)
static float f;
float * fp = f; //check, used a pointer in the code
insert what danny said here, assigning fp to smallest, fp to largest, and
fp the middle value.
one = two = three = 0.0; //affect the incoming variables. I *love* useless requirements, dont you?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center