Please support our C++ advertiser: Programming Forums
Views: 4305 | Replies: 13
![]() |
•
•
Join Date: Sep 2004
Location: Delaware, USA
Posts: 417
Reputation:
Rep Power: 5
Solved Threads: 0
Need a little help here. Seems as if whenever I run the program, it closes before showing the results.
Here is the code below:
What can I do to keep the program running using Command Prompt.
Here is the code below:
//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 12
//
#include <stdio.h>
#include <iostream.h>
int main(int nNumberofArgs, char* pszArgs[])
{
// enter the temperature in Celscius
int celsius;
cout << "Enter the temperature in Celcius:";
cin >> celsius;
// calculate conversion factor for Celsius to Fahrenheit
int factor;
factor = 212 - 32;
// use conversion factor to convert Celsius into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;
// output the results
cout << "Fahrenheit value is:";
cout << fahrenheit;
return 0;
}What can I do to keep the program running using Command Prompt.
Need Website Work... PM Me or EMail Me at mdstreetsoulja@gmail.com ... I am AVAILABLE!
What compiler are you using? I had this problem way back, when I was in learning phase and used Turbo C++, and I had to stop it manually, in MS Visual C++ console applications, it is handled automatically.
You can use
in the end or its equivalent to stop it. (and if it didn't work, then you can do what I did, I used getch() and displayed a messaged myself when I used Turbo C 3.0
)
You can use
system("pause");in the end or its equivalent to stop it. (and if it didn't work, then you can do what I did, I used getch() and displayed a messaged myself when I used Turbo C 3.0
) Regards,
Ejaz.
Ejaz.
•
•
Join Date: Sep 2004
Location: Delaware, USA
Posts: 417
Reputation:
Rep Power: 5
Solved Threads: 0
I use GNU C++ Compiler, really need to get MS Visual C++ so everybody says its EXCELLENT.
Need Website Work... PM Me or EMail Me at mdstreetsoulja@gmail.com ... I am AVAILABLE!
•
•
Join Date: Sep 2004
Location: Delaware, USA
Posts: 417
Reputation:
Rep Power: 5
Solved Threads: 0
Unfortunately pal, that didnt work, sucks I know. Any other method?
Need Website Work... PM Me or EMail Me at mdstreetsoulja@gmail.com ... I am AVAILABLE!
>system("pause");
>put getch();
You know what I find funny? The fact that every time this question is asked, the first two replies suggest the first two absolute worst options. :rolleyes: system is slow, nonportable, and a serious security hole and getch is the patron saint of nonportable.
>What can I do to keep the program running using Command Prompt.
The first thing you need to do is start using correct C++. iostream.h is not a C++ header, so either your compiler is frightfully old, or you aren't learning from the right source. Here is the corrected code with one solution for your command line problem:
Other (cooler) alternatives involve such creations as:
and
If none of these solves your problem then either you aren't doing it right, or your problem is different than the common issue of running a program from within an IDE where the IDE opens a new console window and closes it immediately after the program finishes.
>put getch();
You know what I find funny? The fact that every time this question is asked, the first two replies suggest the first two absolute worst options. :rolleyes: system is slow, nonportable, and a serious security hole and getch is the patron saint of nonportable.
>What can I do to keep the program running using Command Prompt.
The first thing you need to do is start using correct C++. iostream.h is not a C++ header, so either your compiler is frightfully old, or you aren't learning from the right source. Here is the corrected code with one solution for your command line problem:
//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 12
//
#include <iostream>
using namespace std;
int main()
{
// enter the temperature in Celsius
int celsius;
cout << "Enter the temperature in Celsius: ";
cin >> celsius;
// calculate conversion factor for Celsius to Fahrenheit
int factor;
factor = 212 - 32;
// use conversion factor to convert Celsius into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;
// output the results
cout << "Fahrenheit value is: " << fahrenheit << endl;
// remove extraneous characters from the input stream
char ch;
while ( cin.get ( ch ) && ch != '\n' )
;
// pause until the user hits Enter
cout << "Press Enter to continue...";
cin.get();
}#include <limits> // remove extraneous characters from the input stream cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
// remove extraneous characters from the input stream cin.ignore ( cin.rdbuf()->in_avail() );
I'm here to prove you wrong.
•
•
Join Date: Sep 2004
Location: Delaware, USA
Posts: 417
Reputation:
Rep Power: 5
Solved Threads: 0
I dont think its the book source, the book is great. Possibly the C++ program. I am trying to save up for Microsoft Visual C++ "Standard". Do you think thats a good C++ Compiler?
Need Website Work... PM Me or EMail Me at mdstreetsoulja@gmail.com ... I am AVAILABLE!
>I dont think its the book source
Unfortunately, you can only accurately judge the quality of a book if you know the topic it covers intimately. If your book uses <iostream.h> then it's too old to be used as a book to jumpstart your learning.
>the book is great.
I'm getting flashbacks to when beginners were hailing the godawful books of Herbie Schildt because they were easy to understand. *shudder*
>I am trying to save up for Microsoft Visual C++ "Standard".
There are free compilers that are high quality and support the latest C++ standard. Lack of cash is no excuse, I'm afraid.
>Do you think thats a good C++ Compiler?
I use it primarily, and I haven't had any issues with it yet.
Unfortunately, you can only accurately judge the quality of a book if you know the topic it covers intimately. If your book uses <iostream.h> then it's too old to be used as a book to jumpstart your learning.
>the book is great.
I'm getting flashbacks to when beginners were hailing the godawful books of Herbie Schildt because they were easy to understand. *shudder*
>I am trying to save up for Microsoft Visual C++ "Standard".
There are free compilers that are high quality and support the latest C++ standard. Lack of cash is no excuse, I'm afraid.
>Do you think thats a good C++ Compiler?
I use it primarily, and I haven't had any issues with it yet.
I'm here to prove you wrong.
•
•
Join Date: Sep 2004
Location: Delaware, USA
Posts: 417
Reputation:
Rep Power: 5
Solved Threads: 0
Well, I done paid for the C++ book so it doesnt make sense to get another one. Plus, the Accelerated C++ is so-called a great book to learn by, well it was published in the same year as the C++ for Dummies that I have, whats the goodness of it.?
Need Website Work... PM Me or EMail Me at mdstreetsoulja@gmail.com ... I am AVAILABLE!
•
•
Join Date: Sep 2004
Location: Delaware, USA
Posts: 417
Reputation:
Rep Power: 5
Solved Threads: 0
It worked! Great job
Need Website Work... PM Me or EMail Me at mdstreetsoulja@gmail.com ... I am AVAILABLE!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode