#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";
}
C++ Homework Help
Page 1 of 12 Replies - 81 Views - Last Post: 19 November 2012 - 02:37 PM
#1
C++ Homework Help
Posted 19 November 2012 - 02:25 PM
Could somebody please tell me why my degrees Celsius is always zero?
Replies To: C++ Homework Help
#2
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
Re: C++ Homework Help
Posted 19 November 2012 - 02:37 PM
Gah! *facepalm* Well I feel stupid now. Thanks man.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|