# C++ Homework Help

Page 1 of 1

## 2 Replies - 295 Views - Last Post: 19 November 2012 - 02:37 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=300865&amp;s=604e3c177bc62002a499cb7013808e7a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 GrowingDark

Reputation: 3
• Posts: 44
• Joined: 09-March 11

# C++ Homework Help

Posted 19 November 2012 - 02:25 PM

Could somebody please tell me why my degrees Celsius is always zero?

```#include <iostream>
#include <iomanip>

using namespace std;

double input();
double FtoC(double f);
void output(double f, double c);

int main()
{
double f,c;

f = input();
while (f != -999)
{
c = FtoC(f);
output(f,c);
f = input();
}

return 0;
}

double input()
{
double f;

cout << "Please enter degrees fahrenheit (-459.67 or more) or -999 to quit: ";
cin >> f;
while(f < -459.67 && f != -999)
{
cout << "Error! Must be -459.67 or more: ";
cin >> f;
}

return f;
}

double FtoC(double f)
{
double c;
c = (f-32)*(5/9);

return c;
}

void output(double f, double c)
{
cout << endl << endl << f << " degrees fahrenheit is " << c << " degrees celsius\n\n";
}
```

Is This A Good Question/Topic? 0

## Replies To: C++ Homework Help

### #2 sepp2k

• D.I.C Lover

Reputation: 2296
• Posts: 3,551
• Joined: 21-June 11

## Re: C++ Homework Help

Posted 19 November 2012 - 02:33 PM

```c = (f-32)*(5/9);
```

5 and 9 are integers, so 5/9 performs integer division, resulting in 0. This 0 is then converted to double and multiplied with the result of f-32, resulting in 0.0 which is then assigned to c.

To perform the division using floating point arithmetic, at least one of the operands should be a floating point value.

### #3 GrowingDark

Reputation: 3
• Posts: 44
• Joined: 09-March 11

## Re: C++ Homework Help

Posted 19 November 2012 - 02:37 PM

Gah! *facepalm* Well I feel stupid now. Thanks man.