Results 1 to 5 of 5

Thread: Hey i'm getting Errors on thsi simple Convert F to C app, Please help !

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Unhappy

    Hello everyone!
    i have been having troubles trying to compile this program, i ahve been getting around 10-12 errors i'll post the errors after the code.
    Code:
    #include <iostream.h>
    
    float Convert(float);
    int main()
    {
        float TempFer;
        float TempCel;
    
        cout <<"Enter a Ferienthite Degree.";
        cout << "\n Ferienthite.\n";
        cin >> TempFer;
    
        TempCel = Convert(TempFer);
        cout << "here is the temperature in Celcius: ";
        cout << TempCel << endl;
             return 0;
    }
    
        float Convert(TempFer)
        {
        float TempCel;
        TempCel = ((TempFer - 32)*5) / 9;
                return TempCel;
        }

    Errors:
    c:\my documents\c++programs\day5\converttemp.cpp:19: `TempFer' was not declared in this scope
    c:\my documents\c++programs\day5\converttemp.cpp:20: `float Convert' redeclared as different kind of symbol
    c:\my documents\c++programs\day5\converttemp.cpp:3: previous declaration of `float Convert(float)'
    c:\my documents\c++programs\day5\converttemp.cpp:20: syntax error before `{'
    c:\my documents\c++programs\day5\converttemp.cpp:22: ANSI C++ forbids declaration `TempCel' with no type
    c:\my documents\c++programs\day5\converttemp.cpp:22: `TempFer' was not declared in this scope
    c:\my documents\c++programs\day5\converttemp.cpp:23: parse error before `return'

    Can someone tell me what i'm doing wrong?
    thanks for listening


    Note: Compiler i'm using is DevC++ its a GUI

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Here first add using namespace std;
    So you can get the correct library.

    Second you need to tell what kind of var you are passing in function Convert. float Convert(float TempFer)

    Code:
    #include <iostream>
    
    using namespace std;
    
    float Convert(float);
    int main()
    {
        float TempFer;
        float TempCel;
    
        cout <<"Enter a Ferienthite Degree.";
        cout << "\n Ferienthite.\n";
        cin >> TempFer;
    
        TempCel = Convert(TempFer);
        cout << "here is the temperature in Celcius: ";
        cout << TempCel << endl;
             return 0;
    }
    
        float Convert(float TempFer)
        {
        float TempCel;
        TempCel = ((TempFer - 32)*5) / 9;
                return TempCel;
        }
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Talking Thanks~

    Hey thanks, it worked great!
    but i didn't add using namespace std;

    i heard thats an older way to get the libraries or somthing..whats up with that?
    how do u know when to use "using namespace std;" and when to not use it?

  4. #4
    Guest
    use:

    using namespace std;

    when you use the STL headers:


    cstring
    string
    iostream
    cstdio
    cstdlib
    cctype
    ctime
    algorithm
    fstream


    Note - None of those have the *.h extension

    most platforms support <iostream>

    I think windows is the only one that supports <iostream.h>


    and the STL headers are enclosed in what is called a namespace, the particular one they are in is called std....
    instead of using:

    Code:
    #include <iostream>
    
    int main()
    {
    std::cout << "hello";
    return 0;
    }
    you could do:

    Code:
    #include <iostream>
    using std::cout;
    
    int main()
    {
    cout << "hello";
    return 0;
    }
    but you would still have to use:

    Code:
    srd::cin >> var;
    so you would just use the whole namespace:

    Code:
    using namespace std;

  5. #5

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Talking hey thanks for all your help!

    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width