Running A Program in Windows wont work for me!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ff2
    New Member
    • Sep 2006
    • 1

    Running A Program in Windows wont work for me!!

    Ok i'm using Borland CBX and Windows XP. My program is to convert farenheit to celsius. I got the code off the CD that came with "Sams Teach Yourself C++ in 24 Hours" so i doubt the code is wrong. I can run it fine in the IDE but i can run the .exe in Windows XP but when i type in the temperature, say 120 and then press enter it closes the window(it opens by default in the commandline)

    I know that its not the program because I have tried others and they don't work either.

    This is my source code
    #include <iostream>



    float Convert(float);



    int main()

    {

    float TempFer;

    float TempCel;



    std::cout << "Please enter the temperature in Fahrenheit: ";

    std::cin >> TempFer;

    TempCel = Convert(TempFer );

    std::cout << "\nHere's the temperature in Celsius: ";

    std::cout << TempCel << std::endl;

    return 0;

    }



    float Convert(float TempFer)

    {

    float TempCel;

    TempCel = ((TempFer - 32) * 5) / 9;

    return TempCel;

    }
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    Add
    Code:
    system("PAUSE");
    before the last line in your main program (return 0;). What happens is that it does the calculation, then the program prints the result, then it exits and closes the window. When you add the line of code I suggest, it will say "WAIT for user to press a key" before exiting and closing. Then the program won't disappear until you press a key.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Or alternitively rather than running the program directly from Windows (via explorer?) start acommand prompt and then run the program. Because the command prompt already exists it wont exit when the program exits.

      Comment

      Working...