+ 1

Can anyone tell me why this code doesn't work?

void hei(double, double, double); int main() { double h, R, M; cin >> h, R, M; if(h>3){cout << "what are you, kangoroo?";return 0;} if(h<=0){cout << "do you know meaning of word \"jump\"?";return 0;} hei(h, R, M); return 0; } void hei(double h, double R, double M) { long double h1, g; R*=R; g=6.67*10000*M/R;//M_10^21(kg), G 10^-11, R^2_10^-6(m).10^4 is left //height~1/g h1=h*9.8/g; cout << "on that planet you can jump to " << h1 << " meters"; }

3rd Dec 2017, 9:06 AM
Nika Miruashvili
8 Answers
+ 6
@Nika, are you running this code in Code Playground? because if you are, I have faced same situation before, here in SL Code Playground long double is not fully supported, if you think you can do with double, then resort to using double instead of long double. To test my confession validity, you can write a code that declares, then assign a value to a long double type, and try to print the value, I have seen -0 or NAN as output from printing long double. Hth, cmiiw
3rd Dec 2017, 10:00 AM
Ipang
+ 2
that is why i created function prototype. function gets called, that is not the problem.
3rd Dec 2017, 9:13 AM
Nika Miruashvili
+ 2
it just always puts 0 as answer
3rd Dec 2017, 9:13 AM
Nika Miruashvili
+ 2
i was showing how high can you jump on different planets(you enter radius and mass of those planets). and thank you for answers, it worked
3rd Dec 2017, 11:01 AM
Nika Miruashvili
+ 1
you cant define function after main function. Codes are running from top to bottom
3rd Dec 2017, 9:10 AM
Mustafa K.
Mustafa K. - avatar
+ 1
Actually I couldnt understand what are you trying to do with this code?
3rd Dec 2017, 9:18 AM
Mustafa K.
Mustafa K. - avatar