Jump to content
  • Advertisement
Sign in to follow this  
DKSolo

Problem in Dev C++

This topic is 4825 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

I am having a problem in Bloodshed Dev C++. I'm using "Beginning C++ Game Programming" To learn C++. In programs like the following I take user input using "cin." In the program the last time in takes input I type in my input press enter and the game closes. In the following program it closes whenever I enter my last name. Can someone please test it out and see whats wrong? // Lost Fortune // A personalized adventure #include <iostream> #include <string> using std::cout; using std::cin; using std::endl; using std::string; int main() { const int GOLD_PIECES = 900; int adventurers, killed, survivors; string leader; //get the information cout << "Welcome to Lost Fortune\n\n"; cout << "Please enter the following for your personalized adventure\n"; cout << "Enter a number: "; cin >> adventurers; cout << "Enter a number, smaller than the first: "; cin >> killed; survivors = adventurers - killed; cout << "Enter your last name: "; cin >> leader; cout << "\nA brave group of " << adventurers << " set out on a quest "; cout << "-- in search of the lost treasure of the Ancient Dwarves. "; cout << "The group was led by that legendary rogue, " << leader <<".\n"; cout << "\nAlong the way, a band of marauding ogres ambushed the party."; cout << "All fought bravely under the command of " << leader; cout << ", and the ogres were defeated, but at a cost. "; cout << "Of the adventurers, " << killed << " were vanquished, "; cout << "leaving just " << survivors << " in the group.\n"; cout << "\nThe party was about to give up all hope. "; cout << "But while laying the deceased to rest, "; cout << "they stumbled upon the buried fortune. "; cout << "So the adventurers split " << GOLD_PIECES << " gold pieces."; cout << leader << " held on to the extra " << (GOLD_PIECES % survivors); cout << " pieces to keep things fair of course.\n"; return 0; }

Share this post


Link to post
Share on other sites
Advertisement
i think you want this...

//include this header for system()
#include <cstdlib>
...
//right before the return 0; at the end..
system( "pause" );
return 0;

Share this post


Link to post
Share on other sites
Too time I've seen this. Nothing wrong with the program. it display the text and then
return 0;
it ends! If you want to keep the dos prompt open you can do 2 things:
1) windows button + r -> cmd -> find the folder in wich the program is located -> run it
2) add after the "return" a
char blah;
cin >> blah;
in order to make something like "press a button to exit". The system will not close the window until a last input is given

Share this post


Link to post
Share on other sites
well in DevC++ you can use:

system("PAUSE");
return EXIT_SUCCESS;

but it is better to add:

cout << "Press Any Key to Exit";
char something;
cin >> something;

Both of these keep it open until the user presses a button.

Share this post


Link to post
Share on other sites
I'm new to c++ myself but wouldn't your program open and close almost instantly, you should throw a system("PAUSE"); before the return in main
I dought I helped any =( but I wish you the best of luck.

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!