Why does it output strange numbers... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Why does it output strange numbers...

in my most recent code , when you try to convert numbers, the conversion works fine... but in the next line, it outputs "4620160"... what's with these numbers anyway? :/ I would appreciate your help... thx https://code.sololearn.com/cj41FDj2fO3m/?ref=app https://code.sololearn.com/cj41FDj2fO3m/?ref=app

22nd Jul 2017, 4:12 AM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
3 Answers
+ 3
Undeclared variables that aren't static can give undefined behaviour. On SoloLearn this would be outputting the maximum value of the datatype. Notice the functions you wrote are of type int, however they don't return a value!! 😰 This can be fixed by making the functions void. (Which is what it looks like you intended to do). Then, you can just call the function instead of printing it's value. Like: case 'c': tempCtoF(c); break; case 'f' : tempFtoC(c); etc... The program works perfectly after that fix. Great code!
22nd Jul 2017, 4:40 AM
Rrestoring faith
Rrestoring faith - avatar
+ 6
the line/s cout<< tempCtoF cout<<tempFtoC are the problem. they have a return type of int but never return a value. thus a junk value is printed. use void tempCtoF(int c) then tempCtoF; without a cout or return a value using the return keyword.
22nd Jul 2017, 4:35 AM
jay
jay - avatar
+ 3
thx guys
22nd Jul 2017, 6:06 AM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar