Hi all, I've got a problem with a formula that I am trying to use to convert from F to C. Seems that 5 / 9 always returns a zero. Any suggestions?? Here is the code...
#include <iostream>
#include <string.h>
usingnamespace std;
void convert_toc (double *p);
void convert_tof (double *p);
double a;
char b;
int main()
{
while (1){
cout << "Enter C to convert from Centigrade to Fahrenheit or F to do the opposite: ";
cin >> b;
cout << endl;
if (b == 'C' || b == 'c'){
cout << "Please enter a Centigrade temperature to be converted to Fahrenheit (0 = EXIT): ";
cin >> a;
if (a == 0)
break;
cout << "\n";
cout << "\n";
cout << a << " degrees in centigrade is equal to ";
convert_tof(&a);
cout << a << " degrees in Fahrenheit.\n";
cout << "\n";
}
else {
cout << "Please enter a Fahrenheit temperature to be converted to Centigrade (0 = EXIT): ";
cin >> a;
if (a == 0)
break;
cout << "\n";
cout << "\n";
cout << a << " degrees in Fahrenheit is equal to ";
convert_toc(&a);
cout << a << " degrees in Centigrade.\n";
}
return 0;
}
}
void convert_tof (double *p) {
*p = (*p * 1.8) + 32;
}
void convert_toc (double *p) {
*p = (*p - 32) * (5 / 9); /** Something is wrong with this code. For some reason (5 / 9) always causes a return of zero **/
}