- 1

Does the following code works if the variables are float or double?

Does the following code works if the variables are float or double? int greatest(float a, int b, int c) { (a >= b && a >= c) { return a; } if (b >= a && b >= c) { return b; } else { return c; } }

23rd Jan 2017, 11:20 AM
Hassan Ahmadi
Hassan Ahmadi - avatar
6 odpowiedzi
0
why not?
23rd Jan 2017, 11:25 AM
Hassan Ahmadi
Hassan Ahmadi - avatar
0
is this c++??s sure the code won't work if it's like this!
23rd Jan 2017, 11:26 AM
Med amine BORNI
Med amine BORNI - avatar
0
(a >= b && a >= ) { what are you trying to compare here? and return ; is empty and won't return anything in the else statement!
23rd Jan 2017, 11:27 AM
Med amine BORNI
Med amine BORNI - avatar
0
you are right, I corrected that.
23rd Jan 2017, 11:30 AM
Hassan Ahmadi
Hassan Ahmadi - avatar
0
(a >= b && a >= c) ??? nothing happens here it should be if (a >= b && a >= c) . also why do you want to compare a float with int why not making all the variables int ?
23rd Jan 2017, 11:35 AM
Med amine BORNI
Med amine BORNI - avatar
0
also why making a function for that just do it in the main() section! example: int a=10; int b=5; int c=9; { if(a >= b && a >=c) { cout<< a; } else if (b >= a && b >= c) { cout<< b; } else { cout<< c; } } } //// also you can make it work with both!
23rd Jan 2017, 12:03 PM
Med amine BORNI
Med amine BORNI - avatar