454,500 Members | 1,769 Online
Need help? Post your question and get tips & solutions from a community of 454,500 IT Pros & Developers. It's quick & easy.

# basic C++ conversion program help

 P: 19 Hi here is the problem when my program tries to convert Fahrenheit to Celsius it gives an answer of zero regardless of what degree you put in. Any help in solving this is much appreciated. Expand|Select|Wrap|Line Numbers #include  using namespace std;   int main (void)   {     double inch_feet, inch_yard, inch_cent, inch_meter, fahrenheit;       double inch_cv_feet;     double inch_cv_yard;     double inch_cv_cent;     double inch_cv_meter;     double Celsius;       cout.setf(ios::fixed);     cout.setf(ios::showpoint);     cout.precision(2);         cout << " Please enter temperature in Fahrenheit to convert to Celsius: ";     cin >> fahrenheit;     Celsius = (100/180) * (fahrenheit - 32);     cout << " Conversion from Fahrenheit to Celsius is: " << Celsius << endl;       cout << " \nThank you for using this program.\n";       return 0;   }   Nov 7 '08 #1
3 Replies

 Expert 100+ P: 849 The problem is in line 41. When C++ does integer division, it returns an integer. Thus, when you do 100/180, you get 0. To fix this, declare Celsius as a double or float and make one (or both) of the constants .0 so that the compiler knows you mean a decimal value. Nov 7 '08 #2

 P: 19 Hey it worked thanks for the quick reply to my problem and the explanation of what I was doing wrong it is much appreciated. Nov 7 '08 #3

 Expert Mod 5K+ P: 8,916 When posting homework please remember not to post your full code only the relevent bit you are having a problem with. Please read the posting guidelines Nov 7 '08 #4