shiffman / LearningProcessing

A repo for examples from the book Learning Processing
http://learningprocessing.com
606 stars 276 forks source link

07-08 Fahrenheit #211

Open TKerem opened 7 years ago

TKerem commented 7 years ago

I can't understand the Exercise 7-8

Please help me to find the solution.

This is my code, but the result is always 0.0

void setup (){ size(200,200); }

void draw () { float result = convertToCelsius(100); println(result); }

float convertToCelsius(float F){ float c = (F - 32) * (5/9); return c; }

itubal commented 7 years ago

Try with all numbers floats.

100.0, 32.0, 5.0, 9.0 May be the error. Try to "debug" your program. Print the F in the beginin of convertToCelsius() (before float c...), print c after this line. Ah! don't put variables in uppercase.

TKerem commented 7 years ago

The skect doesn't work. I try a lot of numbers but I don't understand where is the problem.

itubal commented 7 years ago

did you make the corrections that I wrote? What is the value of "c" ?

2017-07-03 11:26 GMT+02:00 TKerem notifications@github.com:

The skect doesn't work. I try a lot of numbers but I don't understand where is the problem.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/shiffman/LearningProcessing/issues/211#issuecomment-312595929, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAuj53-rGzUaAUlyGzZVgQb1-ERzk8vks5sKLO9gaJpZM4OLqhS .

-- José María @itubalibre http://itubal.github.io/ http://itubalstyle.blogspot.com

ghost commented 7 years ago

I have the answer here:

void draw(){ float answer = tempConverter(46); println(answer); }

float tempConverter(float f){ float c = (f - 32.0)*(5.0/9.0); return c; }


the float values must have decimals so they can be read properly.

:)

TKerem commented 7 years ago

Thanks !!