Write a function that takes one argument-F for Fahrenheit-and computes the result of the following equation (converting the temperature to Celsius).

C = (F – 32) * (5 / 9)

______ tempConverter(float ________) {
  _____ _______ = ______________
  _____________________________
}

Answer:

void setup() {
  float temp = tempConverter(50);
  println(temp);
}

float tempConverter(float farenheit) { 
  float celsius = (farenheit - 32) * (5.0/9.0);
  return celsius;
} 
  • Aaron

    Quick question here -

    In the “Answer,” shouldn’t it read:

    float celsius = (farenheit – 32) * (5.0/9.0);

    I could be wrong, but just wanted to check. Thanks!

  • admin

    Yup, that’s right! Thanks, fixed now.

  • http://www.mkdesigns.net/ Mary

    I was tripped-up by the fractions needing to have a decimal point to work. Without the decimal point
    on the 5/9 equation I was returning a 0.

    I guess I should include a decimal on all floats just to be safe?

  • http://www.learningprocessing.com Daniel Shiffman

    Indeed, Processing will assume numbers are integers and you want an integer back unless you indicate a float with the decimal value (even if it is “point zero”).

  • Rhys Harris09

    This had me stumped for ages! In France with no Internet, now in a @Cafe and have found the answer! Phew! Thanks!

  • Chuckmahoney

    If you leave out the parentheses around the 5/9, then the calculation will work even if they are integers, due to the order of operations. It will first multiply by 5, then divide by 9. If you write it as above then yes, you must use floats.

  • Rosie Sanchez

    jarely lopez is a stupid fool

  • Rosie Sanchez

    Fuck your shit

  • Rosie Sanchez

    Leslie sucks weiner.

  • Rosie Sanchez

    i, rosie E. Sanchez is a whore

  • jack Smith

    i think this is the most ratchet thing ever you help with nothing, where did you go to high school because you probably didn’t make it to college. See ya!

  • jack smith

    Rosie Sanchez is soooo dumb!

  • rosie sanchez

    mmm, me so horny

  • jack smith

    Enrique Lopez is soo dumb. Jarely Lopez is way smarter. Jarely Lopex at least graduated Jr. High

  • sanchez

    Jarely LOPEX can not even spell

  • ENRIQUE Lopez

    thas sooo right. PREACH IT!!

  • leslie

    i can blame you for mistakes

  • leslie

    fuck you and blurred lines

  • leslie

    no remorse

  • leslie

    hahhahahahah

  • enrique lopez

    stop ittt. We all do we can’t blame her.

  • jack smith

    jack smith is legit

  • Umair

    wher do we insert the temp that we want to convert?

  • shiffman

    Take a look at this line in setup()

    float temp = tempConverter(50);

    50 is the temperature to be converted.

  • Umair

    void setup() {

    float currency = currencyConverter(0);

    println(dollar);

    }

    float currencyconverter(float rupee){

    float dollar = (float rupee*102);

    return dollar;

    }

    please tell me what is wrong with this?

  • shiffman

    float dollar = rupee*102;

  • Umair

    void setup() {

    float currency = currencyConverter();

    println(dollar);

    }

    float currencyConverter(float rupee){

    float dollar = float rupee*102;

    return dollar;

    }

    still getting an error.
    stuck on this for a week.
    really need help guys…

  • Vanessa

    why do we need 4 floats for this equation? Is there no shorter way to do it?