@line 23 you are doing integer division: 5/9
. The result will be an integer, zero. Make one of them a double: 5.0/9
Damn it, I knew the problem was there but...wasn't it suppose to truncate it or something anyway?
Ah nevermind I see, it gets truncated at the division itself, seems like I still have some to study
Last edited on
This is allowed:
1 2 3 4
|
double celsiusDegrees(double num)
{
return (num - 32) * (5.0/9);
}
|
Last edited on
better version of convertion of temperature
// Convertion of degree Celcius to Farenheit
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{ cout<< "Enter temperature."<<endl;
double F,C;
double temp;
cin>> temp;
cout<<"Enter F if temperature is Fahrenheit; or C if the temperature is in Celsius"<<endl;
double tempType;
cin >> tempType;
if (tempType == 'C') //Convert from Celcius to Fahrenheit
{
cout<< "The equivalent of temperature in Fahrenheit is"<<(9.0/5.0)*C + 32<<endl;}
else if( tempType == 'F') //Convert from Fahrenheit to Celcius
{ cout<< "The equivalent of temperature in Celsius is"<<(F-32)*(5.0/9.0)<<endl;}
else //invalid choose to calculate
cout<< "Invalid choose has been entered"<< endl;
system("PAUSE");
return 0;
}