Why won't my program pause?

This is a discussion on Why won't my program pause? within the C++ Programming forums, part of the General Programming Boards category; I am trying to write a program, but in order to see the end result, I need my program to ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Why won't my program pause?

    I am trying to write a program, but in order to see the end result, I need my program to pause at the end and preferable to use enter to exit.

    I have cin.get() at the end...but it's not working...this is copied right out of my text and it even doesn't work correctly. Sorry for the sloppy programming, but I just plugged this in to see if it would work and it doesn't stop. I have GOT to have it stop at the end to see if my calculations that the program that I am working on is correct.

    Any/all help appreciated. And please, nothing complicated..this is for class and he'll know I jumped ahead.

    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    	int partNumber;
    	int quantity;
    	float unitPrice;
    	float totalPrice;
    
    	cout << fixed << showpoint << setprecision(2);
    
    	cout <<"prt #" << endl;
    		cin >> partNumber;
    
    	cout << "qty ordered" << endl;
    	   cin >> quantity;
    
    	   cout << "unit price" << endl;
    	    cin >> unitPrice;
    
    	   totalPrice = quantity * unitPrice;
    
                     cout << "part" << partNumber << ", quantity" <<    quantity << ", at $" << unitPrice << "each" << endl;
    	cout << "totals $ " << totalPrice << endl;
    
    		return 0;
    		cin.get();
    
    
    }

  2. #2
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    UmeŚ, Sweden
    Posts
    555
    The cin.get() has to be done before the return 0. The return statement in the main function makes the program quit and thus your cin.get() will never get executed.
    Doesn't your compiler warn about that?

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    21
    Shouldn't she use a cin.ignore() before the cin.get() too?

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    14
    You guys ROCK!!

    After moving the return 0 under the cin.get and adding the cin.ignore, it worked like a charm.

    And no, my comiler didn't warn me about the return 0...it just executed the file and the box just disappeared. That's nice to know for a future reference...it's MS Visual Studio .Net 2003.

    Thanks!!!!! so much!!

    Ladysniper

  5. #5
    Noob Coder anderson's Avatar
    Join Date
    Feb 2006
    Posts
    14
    yeah i had the same problem so thanks to everyone here coz the answer u supplied worked perfect for me aswell.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why doesn't this cin.get() pause the program?
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2006, 04:06 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. How do I make my program pause
    By quiksilver9531 in forum C++ Programming
    Replies: 9
    Last Post: 01-23-2002, 06:38 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21