Jump to content
  • Advertisement
Sign in to follow this  
SL33pY_Kr3W

problem with cin

This topic is 5061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I just started C++ programming using the book Beginning C++ Game Programming and I've enjoyed it thus far. I have been using the authors code as a reference but I ran into a problem while trying to compile and run a program the author created to give an example of getting user input. The program works fine until it comes to the part where I have to enter an integer and it will then display my number back to me.. I type an integer in and hit enter. Then the window closes leaving me wondering what happened. I have created a smaller version of the program that (at least I think) isolates my problem. // Game Stats // problem #include <iostream> using namespace std; int main() { int fuel; cout << "\nHow much fuel? "; cin >> fuel; cout << "fuel: " << fuel << endl; return 0; } the display is supposed to look like this (ive given a sample integer): How much fuel? 100 Fuel: 100 But as soon as i type in 100 and hit enter the window closes and i cant see if the program worked correctly. Can anyone please tell me whats wrong with my code and how to fix it?

Share this post


Link to post
Share on other sites
Advertisement
Your codes fine. When you enter your value it runs the last two lines and the program closes because its finished.

To make the program wait before exiting insert
system("pause");
before you return.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!