Thread: problem with c=(f-32)*(5/9)

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    16

    problem with c=(f-32)*(5/9)

    hello, my code works if it is written like i have posted it.
    But when i put two brackets at the red line ( c=(f-32)*(5/9); ) my c variable is always 0,000 .
    Why is that so ?

    Code:
    int
    Code:
    main()
    
    {
    float f,c;
    printf("give temp at Fahrenheit: \n\n");
    scanf("%f",&f);
    c=(f-32)*5/9;
    printf("the temperature in celsius is: %f \n\n",c);
    return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2013
    Posts
    228
    Because (5/9) is 0. And 0 times anything gives 0.

    EDIT

    To be more specific: the expression you are probably looking for is: (f-32)*((float)5/9)
    Last edited by Absurd; 04-02-2016 at 03:54 AM.

  3. #3
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Actually I think I'd prefer (f - 32) * 5.0 / 9

  4. #4
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Hodor View Post
    Actually I think I'd prefer (f - 32) * 5.0 / 9
    Personally, I'd prefer (f - 32) * 5.f / 9

    It's even more hip

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Personally I try to write everything out all the time.

    c = (f - 32.0f) / 1.8f;

  6. #6
    Registered User
    Join Date
    Apr 2016
    Posts
    16
    Ok.! my problem was just hilarious! thank you very much!!! 8-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-09-2014, 06:46 PM
  2. Problem passing argument into function, basic problem
    By tsdad in forum C++ Programming
    Replies: 7
    Last Post: 05-22-2013, 12:09 PM
  3. Replies: 2
    Last Post: 01-06-2013, 07:49 AM
  4. Replies: 1
    Last Post: 12-07-2012, 10:00 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM