Archived

This topic is now archived and is closed to further replies.

the window keeps disappearing.!!!!!!

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

Use MS-Dos to initiate the program. There are ways to change your source to fix this too, but I just prefer this way.

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

Share this post


Link to post
Share on other sites
This might work. Call wait() before exiting main().

    
#include <iostream>

using namespace std;
void wait()
{
cout << endl << "Press <enter> to continue";
char enter;
cin.getline(&enter, 1);
}


[edited by - WoR on September 10, 2002 6:27:23 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by articwolf3805
yea zealous but there has to be a way to make the window stay up without putting a system pause on it


arcticwolf, I think what you are trying is best answered with some previous suggestions in your other post. Mainly getting a book to help learn the language.

The reason your window is closing so quickly is because you haven't told the code to do anythign else. The code starts at main() and goes line by line as fast as possible until it's done. If you tell it to PAUSE somewhere, it will, but as soon as it's done it will continue on. When it hits the end of the main() procedure, it's going to close like it is.

So you need to learn about loops and control statements, and figure out what you are trying to do... If you are interested in making a game, start out with a High/Low Guess the number style of game. This is probably one of the easiest to create.

I'll try to help you get started... Here is some flow statements to show how the program would be designed...


01) PROGRAM START ( main() )
02) Random Number Generator is seeded (srand(time(NULL)
03) Program picks a random #
04) Start a While Loop that waits until the user guesses the number.
05) Program Displays a prompt to the user, asking him to pick a number
06) Program checks the users input to see if it's higher or lower than the random number.
07) If Higher, Tell the user he was too high, and loops back to 04.
08) If Lower, Tell the suer he was too low, and loop back to 04.
09) If Guessed, then exit out of the While loop.
10) After the while loop, Congratulate the player for guessing the number.
11) End Program


Now, to write this program, you are going to have to know how to use a few commands, I think the following would be sufficient.


      
srand(time(NULL)); //You probably won't have to worry about knowing what this means right now. But any program that uses RANDOM NUMBERS has to have this in the main() function, or the random numbers will always be the same. Also, you will need to #include <time.h> for this to work.


if( statement ) {}; // The IF statement is one of the most important to any programming language. Look around for sample programs to see it's format.


cin; and cout; //These are used to input and output characters to the screen. the format is a little strange, but goes like this...

//examples

cout<<"Hello"; //Outputs Hello


int a_var; //Creates an integer variable called 'a_var'

cin>>a_var //takes whatever the user types and stores it in 'a_var'

/////////


while() //The while statement is a control statment that causes a loop while a certain variable condition is true.



That SHOULD be enough commands to create the Guess the Number Program.. I might of left something simple out though... I hope I haven't rambled too much, and hopefully this post is at least somewhat helpful.

If you have any questions, post away!




~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
--edit typo

[edited by - Radagar on September 10, 2002 8:19:42 PM]

[edited by - Radagar on September 10, 2002 8:20:56 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by articwolf3805
yea zealous but there has to be a way to make the window stay up without putting a system pause on it


You, sir, are wrong. Additionally, you have no understanding of how your command line interpreter functions, nor do you understand the process of program execution. The ONLY way to make your "window" persist is to run it from the command line, or insert code that causes it to wait for input before it terminates.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

Share this post


Link to post
Share on other sites