# Convert Celsius to Fahrenheit

Page 1 of 1

## 4 Replies - 9390 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=1966bd9d554463992f140ac75f8f37cd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 pun_indo

• New D.I.C Head

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;

}

```

please help me. tell me what I did wrong.

thanks

Is This A Good Question/Topic? 0

### #3 Martyr2

• Programming Theoretician

Reputation: 4818
• Posts: 13,084
• 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!"
Was This Post Helpful? 1

### #4 pun_indo

• New D.I.C Head

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

Was This Post Helpful? 0

### #5 programble

• (cons :dic :head)

Reputation: 51
• 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.
Was This Post Helpful? 0

### #6 pun_indo

• New D.I.C Head

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 .
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }