Likes: 0
Results 1 to 6 of 6
Thread: Pausing a C++ Program
-
30-03-10, 03:26 AM #1
Pausing a C++ Program
Register to remove this adGreetings everyone!
I'm currently trying to grasp the basics of C++. I've been using 'system("PAUSE")' to pause a program but according to a number of programmers, this is a rather bad habit. Is there a better, more efficient way to pause a program please? I'm currently using Visual Studio 2008.
Help is always much appreciated.
› See More: Pausing a C++ Program
-
30-03-10, 08:10 AM #2
Why would you need to pause a program?
-
30-03-10, 08:29 AM #3
Let's take this program as an example:
In this case, a pause is needed after displaying the result or else the program would instantly close without allowing the user to see it. Should I stick to 'system("PAUSE")' for simple programs?Code:// This programs converts feet to metres or vice versa #include <iostream> using namespace std; int main () { short userchoice; double metres; double feet; cout << "To convert feet to metres, please press 1\n"; cout << "To convert metres to feet, please press 2\n"; cin >> userchoice; cout << "\n"; if (userchoice == 1) { cout << "Please enter the number of feet: "; cin >> feet; metres = feet/3.28; cout << feet << " feet = " << metres << " metres\n"; } if (userchoice == 2) { cout << "Please enter the number of metres: "; cin >> metres; feet = metres*3.28; cout << metres << " metres = " << feet << " feet\n"; } cout << "\n"; system("PAUSE"); return 0; }
-
01-04-10, 02:58 AM #4
-
01-04-10, 06:56 AM #5
Thanks for the tip mate!
-
09-04-10, 11:10 PM #6Banned

- Rep Power
- 0
- Reputation
- 68
Register to remove this adyou could create a loop that after the program is run, it asks if the user wants to run the program again. If so loop to the beginning, if not the program exits.






Reply With Quote







