+ 2

Why isn't the printf and return statement outputting the same value for results?

using c/c++, on codeblocks 17.12 https://code.sololearn.com/cMTJ1J31ycqD/?ref=app

13th May 2018, 7:10 AM
Otumian Empire
Otumian Empire - avatar
7 Antworten
+ 1
Oh I see. In your code it gives good results, but you have to get paranthesis good. Use: (-b + sqrt(...)) / (...). If you wont put () around first expression the divide will evaluate first and then add -b to it.
13th May 2018, 7:29 AM
Jakub Stasiak
Jakub Stasiak - avatar
0
Return isn't used for printing out the result on console. It just returns value, so you can assign it to variable or pass as an argument.
13th May 2018, 7:13 AM
Jakub Stasiak
Jakub Stasiak - avatar
0
that's right, but i could output it directly.. int age(int age) { return age; } int main() { cout<<"i am " <<age(1000) <<" years old"<<endl; return 0; }
13th May 2018, 7:21 AM
Otumian Empire
Otumian Empire - avatar
0
you can do int val = age(1000); cout<<"age: "<<val; return only assign a value to variable or printing this value that return
13th May 2018, 7:27 AM
Daniel Oseguera
Daniel Oseguera - avatar
0
its a solution to someone, and i want it to be much more readable..
13th May 2018, 7:45 AM
Otumian Empire
Otumian Empire - avatar
0
its a solution to someone, and i want it to be much more readable..
13th May 2018, 7:45 AM
Otumian Empire
Otumian Empire - avatar
0
found the error instead of %.2f i wrote %2.f
13th May 2018, 9:36 AM
Otumian Empire
Otumian Empire - avatar