Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing fahrenheit to kelvin in C

Tags:

c

I'm trying to change fahrenheit to Kelvin anf the formula is K = 5/9 (° F - 32) + 273

My code is:

#include <stdio.h>
double const changeToC = 32.0;
double const changeToK = 273.16;

void temperatures(double n);

int main(void)
{
    int q = 'q';
    double userNumber;

    printf("please enter fahrenheit number: \n");
    scanf("%f", &userNumber);

    while (userNumber != q)
    {
        temperatures(userNumber);
        printf("\n");
        printf("please enter fahrenheit number: \n");
        scanf("%f", &userNumber);
    }
}

void temperatures(double n)
{
    double celsius, kelvin;

    celsius = 5.0 / 9.0 * (n - changeToC);
    kelvin = 5.0 / 9.0 (n - changeToC) + changeToK;

    printf("fahrenheit is: %.2f - celsius is: %.2f - kelvin is: %.2f", 
           n, celsius, kelvin);
}

I need the input to get a fahrenheit in double, and print the value of celsius and kelvin.

In the fahrenheit to kelvin(kelvin = 5.0 / 9.0 (n - changeToC) + changeToK;) line I'm getting an error:

called object type double is not function or function pointer

Can you please tell me what this means?

like image 962
MNY Avatar asked Jan 20 '13 18:01

MNY


People also ask

What is the formula for converting Fahrenheit to Celsius C?

F° to C°: Fahrenheit to Celsius Conversion Formula To convert temperatures in degrees Fahrenheit to Celsius, subtract 32 and multiply by . 5556 (or 5/9).

How do you convert temperature to Kelvin?

How do you convert Celsius to Kelvin formula? The conversion of Celsius to Kelvin: Kelvin = Celsius + 273.15.


Video Answer


1 Answers

You missed the multiplication operator, *

kelvin = 5.0 / 9.0 * (n - changeToC) + changeToK;

Without the multiplication operator, the compiler treats the parentheses () as the function call operator.

like image 109
David Heffernan Avatar answered Sep 28 '22 07:09

David Heffernan