Thread: Fahenhieght?

  1. #1
    Pokemon Master digdug4life's Avatar
    Join Date
    Jan 2005
    Location
    Mystic Island, NJ
    Posts
    91

    Question Fahenhieght?

    I'm makeing a converter, but it wont compile
    Code:
    #include <iostream>
    
    int far ( int x )
    {
     return (x-32)*(5/9);
    }
    
    int cel ( int x )
    {
     return x+32*(9/5);
    }
    
    using namespace std;
    
    int faren();
    
    int cels();
    
    int main ()
    {
      int input;
      
      cout<<"1. Celsius to Fahrenheit\n";
      cout<<"2. Fahrenheit to Celsius\n";
      cout<<"Selection: ";
      cin>> input;
      switch ( input ) {
      case 1:            
        cels();
        break;
      case 2:            
        faren();
        break;
      default:            
        cout<<"Error\n";
        break;
      }
    
    int faren {
      
      int x;  
      cout << "Temperature Farenhieht:";
      cin>> x;
      cin.ignore();
      cout << "Celsius:" << far(x);
      cin.get();
      }
      
    int cels(){
      int x;  
      cout << "Temperature Celsius:";
      cin>> x;
      cin.ignore();
      cout << "Fahrenheit:" << cel (x);
      cin.get();
      }
    Someone tell me what's wrong!
    Verbal Irony >>

    "I love english homework!" When really nobody like english homework.
    -Mrs. Jennifer Lenz (English Teacher)

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    what are your errors?

  3. #3
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    You forgot to close int main()
    }
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Clear result of the weird indentation. Always have opening and closing braces of blocks at the same indent level, unless the opening brace is at the end of a line. In that case, have the closing one at the level of that line.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    And btw. to get from Celcius to Fahrenheit the algorithm is " Fahrenheit = ((Celcius*1.8)+32), that why 0 Celcius is 32 Fehrenheit.
    If you have to get Celcius, just solve Celcius in the equation above.
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  6. #6
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    The equations 5 / 9 which will always result in zero, and 9 / 5 will also produce undesirable results. The compiler identifies them as integers. Change them to floating point numbers 5.0 / 9.0 to get the proper results.

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    44
    And close int main().. LOL

  8. #8
    Pokemon Master digdug4life's Avatar
    Join Date
    Jan 2005
    Location
    Mystic Island, NJ
    Posts
    91
    I got it!!!!!!!!!
    Code:
    #include <iostream>
    
    float far ( float x )
    {
     return (x-32)*(5.0/9.0);
    }
    
    float cel ( float x )
    {
     return (x*1.8)+32;
    }
    
    using namespace std;
    
    int faren();
    
    int cels();
    
    int main ()
    {
      int input;
      
      cout<<"1. Celsius to Fahrenheit\n";
      cout<<"2. Fahrenheit to Celsius\n";
      cout<<"Selection: ";
      cin>> input;
      switch ( input ) {
      case 1:            
        cels();
        break;
      case 2:            
        faren();
        break;
      default:            
        cout<<"Error\n";
        break;
      }
    }
    
    int faren() {
      
      float x;  
      cout << "Temperature Farenhieht:";
      cin >> x;
      cin.ignore();
      cout << "Celsius:" << far(x);
      cin.get();
      
    int input2;
    cout<<"Start over 1.yes / 2.no :\n";
      cin>> input2;
      switch ( input2 ) {
      case 1:            
        main();
        break;
      case 2:            
        cout:"/n";
        break;
      default:            
        cout<<"Error\n";
        break;
      }
    }
      
    int cels(){
     
      float x;  
      cout << "Temperature Celsius:";
      cin>> x;
      cin.ignore();
      cout << "Fahrenheit:" << cel (x);
      cin.get();
     int input3;
      cout<<"Start over 1.yes / 2.no :\n";
      cin>> input3;
      switch ( input3 ) {
      case 1:            
        main();
        break;
      case 2:            
        cout:"/n";
        break;
      default:            
        cout<<"Error\n";
        break;
      }
     }
    I know its a bit messy, but it works!
    Verbal Irony >>

    "I love english homework!" When really nobody like english homework.
    -Mrs. Jennifer Lenz (English Teacher)

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    BTW, a big temperature converter is the only finished part of my tutorial. (Don't view with IE!)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed