Need Help...

This is a discussion on Need Help... within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by francusmag ok this does work to perfection pausing the code so that you can read it.... Thank ...

  1. #16
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by francusmag View Post
    ok this does work to perfection pausing the code so that you can read it....
    Thank you guys so much!!!
    Now a new problem arrives... The response to the code after compiling and running is:

    Enter number of gallons: (number entered appears)
    Liters: (answer) (and directly following the last digit of the answer)Press any key to continue...

    Question how can i make that last text after the last digit appear in a new line.
    Code:
    cout << "Liters: " << liters << endl;
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  2. #17
    Registered User
    Join Date
    Nov 2007
    Posts
    18
    Thank you so much.... you guys are great help!

  3. #18
    Registered User
    Join Date
    Jul 2009
    Posts
    20
    There are two ways I know you can do this:
    1) After cin >> gallons; put cin.ignore();
    Then put cin.get(); before return 0;
    Example:
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	int gallons, liters;
    
    	cout << "Enter number of gallons: ";
    	cin >> gallons;
            cin.ignore();
    
    	liters = gallons * 4;
    
    	cout << "Liters: " << liters;
    
            cin.get();
    	return 0;
    }
    2) put system("pause"); before return 0;
    Example:
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
     	int gallons, liters;
       
    
    	cout << "Enter number of gallons: ";
    	cin >> gallons;
        liters = gallons * 4;
    
    	cout << "Liters: " << liters;
    	
    	system("PAUSE");
    	return 0;
    }
    Also, you actually dont even need the return 0; at the end of your int main() function because the int main() function automatically returns 0. Just in case you didn't know.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

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