Archived

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

TheRademaker

[C++] Programm closing/quitting....causing nervous breakdown

Recommended Posts

#include <iostream.h> //preprocessor directive(#include) and a header file(iostream.h) int main (void) { int Guns; //The amount of guns used to shoot the human |Integer Variable int BulletsPerSec; //The amount of bullets leaving the gun per second |Integer Variable int BulletHoles; //Bullet holes created in the body of the human |Integer Variable int TimeInSecs; //The duration of the firing of the guns in seconds |Integer Variable cout <<"\n"; //Indicates "new line", I used it to create severel blank lines cout <<"\n"; cout <<"Number of guns used for shooting? : "; //This(cout) prints the output to the screen cin >> Guns; //This(cin) reads the user input via the keyboard cout <<"\n"; cout <<"Bulletrate of the guns used by the shooters : "; cin >> BulletsPerSec; cout <<"\n"; cout <<"The amount of time the gun fired? : "; cin >> TimeInSecs; cout <<"\n"; BulletHoles = Guns * BulletsPerSec * TimeInSecs; //Calculation of the integer variables// //Method to calculate the amount of bulletholes //in the human. cout <<"Calculated amount of bulletholes in a person's body= "; return BulletHoles; //The amount of bullet holes in the human, calculated by the method //shown above(see comments above) return 0; } When i run the .exe the programm executes before i can even read the BulletHoles value that it should return on the screen. I've tried everything...(within my knowledge) But the programm keep closing....sigh So how can i keep the programm from closing? So that i can easily read the returned outcome of the calculated BulletHoles? [edited by - TheRademaker on August 11, 2002 9:31:28 PM]

Share this post


Link to post
Share on other sites
You can take a few different approaches to it. You can run your program from the command prompt (just type command into the start/run box in windows), you can run the program from a batch file and issue a 'pause' command in the batch file or you can use an input stream that waits for a person to enter a key and hit enter before closing (look into cin), or use the getchar() function. More choices than you can shake a stick at.

HTH

[edited by - SysOp_1101 on August 11, 2002 9:31:01 PM]

Share this post


Link to post
Share on other sites
try this when u are including your header files add
#include
then on the line b4 return 0 add
system("PAUSE"); , and that should fix it
edit: is there a reason why im not aloud to say ? it just blanks it UGH WHY CANT I SAY <-S-T-D-L-I-B-.-H-> ????? ur not the only one have a nervous breakdown rade



[edited by - brainchild on August 11, 2002 9:40:59 PM]

Share this post


Link to post
Share on other sites
Yay...running in command prompt worked.
But why doesn''t it work when you doubleclick the .exe file?
Is it just because the programm executes and is finished...so that it stopt "because" it has finished executing the code?

Share this post


Link to post
Share on other sites
Yep, return(0) is the applications way of saying, "stick a fork in me, I''m done". Once that occurs, since windows specifically created the console window in response to your application opening, it has no need of it once your application is finished and closes it. If something else opened the command window OTOH, it waits for the original process to close before destroying the window (in this case your call to the shell via ''command'' which is terminated with ''exit'').

HTH

Share this post


Link to post
Share on other sites
quote:
Original post by TheRademaker
[b
cout <<"Calculated amount of bulletholes in a person''s body= ";
return BulletHoles; //The amount of bullet holes in the human, calculated by the method
//shown above(see comments above)







You shouldn''t return the value, do this instead:
cout << BulletHoles;
return 0;

Share this post


Link to post
Share on other sites
Guest Anonymous Poster





You shouldn''t return the value, do this instead:
cout << BulletHoles;
return 0;


yep, i fixed that....

Share this post


Link to post
Share on other sites