Thread: Conversion from Fahrenheit to Celsius problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    13

    Conversion from Fahrenheit to Celsius problem

    I'm doing a simple code which converts an entered amount of degrees Fahrenheit to Celsius. I'm running sample test data and there appears to be a converting problem.

    Code:
    //This program will convert a temperature of Fahrenheit  to Celsius
    #include <iostream>
    using namespace std;
    
    //Function Prototypes
    int Celsius(int);
    
    int main()
    {
        int F, // # of degrees Fahrenheit
            C; // # of degrees Celsius
    
        
        cout <<"This program will convert a temperature of Fahrenheit to Celsius." << endl;
        cout <<"Please enter the amount of degrees (integer) Fahrenheit." << endl;
        cin  >> F;
        C = Celsius(F);
        cout << F << " degrees Fahrenheit converted to Celsius is " << C << endl;
    
    
    
    
    system("pause");
    return 0;
    }
    //************************************************
    //Definition of function Celsius.                * 
    //This function converts Fahrenheit to Celsius.  *
    //************************************************
    int Celsius(int F)
    {
    
        return ((5 / 9) * (F - 32)); // Formula used to convert Fahrenheit to Celsius
    
    }
    My first test data was 32 and it came out correctly with a conversion of 0 degrees Celsius. When I tried one (1), it gave me an output of zero (0) as with others numbers I have entered. Can you help me identify the problem?

    Edit:
    I know some answers will come out with a decimal, but I'm only concerned with "whole" numbers.
    Last edited by -Syntax; 01-22-2008 at 01:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  2. Microsoft -> ISO conversion problem
    By murdercityriot in forum C++ Programming
    Replies: 18
    Last Post: 08-07-2008, 09:03 AM
  3. String conversion problem
    By Mr.Bit in forum C Programming
    Replies: 9
    Last Post: 03-04-2008, 04:39 PM
  4. simple currency conversion problem
    By sweetgem in forum C++ Programming
    Replies: 2
    Last Post: 08-01-2002, 12:41 PM
  5. Replies: 2
    Last Post: 02-07-2002, 09:39 AM