>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:
//
// 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();
}
Other (cooler) alternatives involve such creations as:
#include <limits>
// remove extraneous characters from the input stream
cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
and
// remove extraneous characters from the input stream
cin.ignore ( cin.rdbuf()->in_avail() );
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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>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 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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>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
Are you using Accelerated C++ or C++ for Dummies? If it's the former then your interpretation of the code is wrong because Accelerated C++ never uses . If it's the latter, I have no comments because I haven't flipped through that book in some time and current editions may be better.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>Well can sumbody please refer me a good UP-TO-DATE C++ book.
I already have. But if it was written after 2003 then it's probably a safe bet that it's up to date.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401