Jump to content
  • Advertisement
Sign in to follow this  
Brdman78

need C++ help

This topic is 4747 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'm about to go crazy!!! I recently purchased a book called " Beggining C++ game programming " and i am stuck. i just finished writing the program that the chapter 1 questions tell you to write as a test. i wrote the program and it takes three numbers that i input and finds the average. its kind of simple but when i input the third number and hit enter the program automaticly shuts off and i cant see the product of my work(the average of the three input number's average). I can see the average show up for a split second but i cant seem to make it stay so i can see it

Share this post


Link to post
Share on other sites
Advertisement
Just make a temp variable and throw a cin statement before return 0, if you're using a Windows-based operating system you can include stdlib.h and put system("PAUSE") before return 0 at the end of the program instead of cin.

Share this post


Link to post
Share on other sites
Your easiest option is to run the program from the DOS prompt -- use the "cd path\to\directory" command to navigate to the directory the program is in, and then type the name of the program to execute it. Other options include the system PAUSE command, using cin to force the user to press enter before it exits, or using getch() from conio.h to force the user to press any key before it exits.

Share this post


Link to post
Share on other sites
thank you very much you have solved my problem.

alas i have a new problem. just finished creating a small game using random number generators. the game itself works fine but i want to make it ask me to play again and have a y/n input system. the code for play again i already know but i cant seem to combine it with my game to where if you hit y then its starts over and if you hit n it stops. when i hit y it doesnt do any thing can you help me

Share this post


Link to post
Share on other sites
In all games there's a game loop. This game loop handles many things such as input, output etc. but it basically checks whether or not the game is finished.

Here's a very quick example of how to create a game loop:
int done = 0;

while ( done == 0 )
{
/* TODO: Code for your game loop goes here.
This area holds everything your game does whilst it's running. */

}

Share this post


Link to post
Share on other sites
Just use a while loop and some if's and you can do that. I take it you don't know how to create functions yet(you might know how to.) If you do, then create function for plat again, and to quit. If you don't then do it a different way. Just full around, and you might beable to fix it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use a do {} while () loop. Have:

char yesNo = 'y';

do {
// Play the game...

cout>yesNo;
} while (yesNo != 'n' || yesNo != 'N')


Do all that atleast once(the do loop) and update the variable.

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!