Conversion Query

This is a discussion on Conversion Query within the C++ Programming forums, part of the General Programming Boards category; Hey, I'm having trouble with this program. I'm trying to convert degrees F to degrees C with the conversion factor. ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    75

    Question Conversion Query

    Hey, I'm having trouble with this program. I'm trying to convert degrees F to degrees C with the conversion factor. But when I execute the program, degrees C always comes out to 0. Anyone have an idea as to what I'm doing wrong? Here's the program...

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
    	int F, C; 
    
    	cout << "Enter temperature in Fahrenheit: " << flush;
    	cin >> F;
    	cout << endl;
    	
    	static_cast<int>(C = (5/9)*(F - 32));
    
    	cout << "Current temperature = " << F << "F" << endl;
    	cout << "Current temperature = " << C << "C" << endl;
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    your error: 5/9 is an integer devision. the result is 0
    use 5.0 / 9.0 instead

    edit:
    uh...

    you probably want:
    C = static_cast<int>( 5.0 / 9.0 ... )
    signature under construction

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    75
    Thanks!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 06:18 PM
  5. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 09:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21