By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

Running A Program in Windows wont work for me!!

P: 1
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;

}
Sep 19 '06 #1
Share this Question
Share on Google+
2 Replies


100+
P: 293
D_C
Add
Expand|Select|Wrap|Line Numbers
  1. 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.
Sep 19 '06 #2

Banfa
Expert Mod 5K+
P: 8,916
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.
Sep 20 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.