# Convert Celsius to Fahrenheit

Page 1 of 1

## 4 Replies - 10450 Views - Last Post: 03 March 2009 - 07:44 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=90204&amp;s=6606068c3cde8de7445a97518f8ace2d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 pun_indo

Reputation: 0
• Posts: 32
• Joined: 28-February 09

# Convert Celsius to Fahrenheit

Posted 02 March 2009 - 07:38 PM

hi, please help me figure out how can I solve this problem. I am having problems in writing this code.

The question that asks is that :

a) Function celsius returns the Celsius equivalent of a Fahrenheit temperature.

I did that but I think there is some problems, so maybe someone here can help me out

my code
```#include <stdio.h>

int temperature( int c, int f)
{
if (c==0)
return c;
else
return f;
}
int main(void)

{
int celsius, fahrenheit, temp;

printf("Enter temp");
scanf("%d", &fahrenheit);

printf("Enter temp");
scanf("%d", &celsius);

temp=1.8*celsius+32;

printf("temp = %d", temp);

return 0;

}

```

thanks

Is This A Good Question/Topic? 0

### #3 Martyr2

• Programming Theoretician

Reputation: 5187
• Posts: 13,917
• Joined: 18-April 07

## Re: Convert Celsius to Fahrenheit

Posted 02 March 2009 - 10:49 PM

Your formula for the Celsius to Fahrenheit should be IN the function, not in main. Because it is not in the function, what you have there makes really no sense.

```float celsiusToFahrenheit(float celsiusTemp)
{
return ((9.0/5.0) * celsiusTemp) + 32;
}

```

Notice here how we put the formula inside the temperature conversion function and return the answer using the return statement.

Then from main we can call this function and get the answer...

```int main() {
// Call the function and have it return the converted value
float Fahrenheit = celsiusToFahrenheit(23);

printf("After conversion: %.2f",Fahrenheit);
return 0;
}

```

So this should give you the idea of how a function works and how we could use it to do some work for us and get a result from it.

Enjoy!

"At DIC we be temperature converting code ninjas... DIC is in the forecast, expect extreme blizzard conditions with a temperature of absolute zero. Oh yes, we are that cool!"

### #4 pun_indo

Reputation: 0
• Posts: 32
• Joined: 28-February 09

## Re: Convert Celsius to Fahrenheit

Posted 03 March 2009 - 06:46 PM

Thanks a lot sir. I appreciate that . I will try to do more on it and will ask questions if I have any

but can you explain me that why did u put
```float Fahrenheit = celsiusToFahrenheit(23);
```
I did not get it . what does 23 has to do ?

Thanks again

This post has been edited by pun_indo: 03 March 2009 - 07:45 PM

### #5 programble

Reputation: 50
• Posts: 1,315
• Joined: 21-February 09

## Re: Convert Celsius to Fahrenheit

Posted 03 March 2009 - 07:12 PM

23 is the celsius temperature he is telling the function to convert.

### #6 pun_indo

Reputation: 0
• Posts: 32
• Joined: 28-February 09

## Re: Convert Celsius to Fahrenheit

Posted 03 March 2009 - 07:44 PM

ya got it after I played around with the code

thanks though .