Hello & Welcome to our community. Is this your first visit? Register
Follow us on
Follow us on Facebook Follow us on Twitter Watch us on YouTube


MMOCoin

Likes Likes:  0
Results 1 to 6 of 6
  1. #1
    Beginner

    Join Date
    Feb 2010
    Posts
    24
    Post Thanks / Like
    Rep Power
    15
    Reputation
    3

    Pausing a C++ Program


    Register to remove this ad
    Greetings 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

  2. #2
    Banned

    Join Date
    Sep 2009
    Posts
    90
    Post Thanks / Like
    Rep Power
    0
    Reputation
    103
    Why would you need to pause a program?

  3. #3
    Beginner

    Join Date
    Feb 2010
    Posts
    24
    Post Thanks / Like
    Rep Power
    15
    Reputation
    3
    Let's take this program as an example:

    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;
    }
    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?

  4. #4
    Banned

    Join Date
    Sep 2009
    Posts
    90
    Post Thanks / Like
    Rep Power
    0
    Reputation
    103
    Quote Originally Posted by Synapse View Post
    Let's take this program as an example:

    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;
    }
    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?
    I suggest that you download Visual Studio, since you don't need to pause the program if you use it.
    To run the program simply press ctrl + F5

  5. #5
    Beginner

    Join Date
    Feb 2010
    Posts
    24
    Post Thanks / Like
    Rep Power
    15
    Reputation
    3
    Thanks for the tip mate!

  6. #6
    Banned

    Join Date
    Aug 2008
    Location
    Spartanburg, SC
    Posts
    71
    Post Thanks / Like
    Rep Power
    0
    Reputation
    68

    Register to remove this ad
    you 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.




  7. Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread

 

 

Visitors found this page by searching for:

pausing a program in c

pausing visual studio without system(pause)

I need system pause for visual studio to run program

efficient ways of pausing program

c pausing program without system pause

pause c program in visual studio

SEO Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -5. The time now is 06:55 AM.
Powered by vBulletin® Copyright ©2000-2024, Jelsoft Enterprises Ltd.
See More links by ForumSetup.net. Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
vBulletin Licensed to: MMOPro.org