Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

Exiting program from code?

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

Quote:
Original post by orcfan32
Quote:
Original post by Nitage
Then you need to restructure your code. Show us what you have and I'll try to give you some helpful pointers.


Sorry, no can do.


Why not?

Share this post


Link to post
Share on other sites
Advertisement
Fine, in that case use a break statement in conjunction with a boolean, like this:


int completedTask = 0;
while (1){
doStuff();
if ((completedTask = completedEverything()) || failedTask()){
break;
}
}
if (competedTask){
printStuff();
}



In this example, doStuff() does something, I don't care what it does, nor should you. As for completedEverything() and failedTask(), they return booleans (or integers in this case), and if completedEverything() returned true, completedTask would have been set to true, but if either function returned true, it will break from the loop.

The result: printStuff() will only be called if completedEverything() returns true, but the loop will continue on indefinately unless either completedEverything() or failedTask() return true.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oberon_Command
Quote:
Original post by orcfan32
Quote:
Original post by Nitage
Then you need to restructure your code. Show us what you have and I'll try to give you some helpful pointers.


Sorry, no can do.


Why not?


Because he's writing the next generation 3D FPS-RPG-RTS MMO and his code is top-secret. In order for you to view it, you have to sign an NDA and pay him $500,000 to gain access to the source code.

Orcfan: Nobody is able to help you if you don't show some code. If you want to exit your application half way during runtime, just use flags and what-not.

Toolmaker

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
...by using structured exception handling...
Did you mean C++ exception handling? SEH is a Windows system functionality and Microsoft extension to C (via the __try, __except and __finally statements), and not applicable to any programmer who hopes to keep his code portable.

I know you know this, but your audience might not.

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
Because he's writing the next generation 3D FPS-RPG-RTS MMO and his code is top-secret. In order for you to view it, you have to sign an NDA and pay him $500,000 to gain access to the source code.

Orcfan: Nobody is able to help you if you don't show some code. If you want to exit your application half way during runtime, just use flags and what-not.

Toolmaker


LOL... He's right, orcfan. Show us some code, and we'll be able to help you.

Share this post


Link to post
Share on other sites
Quote:
Original post by orcfan32
Can you exit your program with code? (Lang C++, Compiler Dev-C++, OS XP)


Here is my opinion for a console application(this is my speciality):
Take a global variable.
Take a interrupt function to control the application and the variable.

If the value of the variable changes main() will break and return a result.
this is the most simple and efficient exit program with a exit code


I usually use this for my applications and i think is the most fastest




PS sorry for my englesh

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
Because he's writing the next generation 3D FPS-RPG-RTS MMO and his code is top-secret. In order for you to view it, you have to sign an NDA and pay him $500,000 to gain access to the source code.


ROFL! It was a game I was writing, but I discontinued it. Nevermind. It was Tic-Tac-Toe, and it didn't work right, but I was fixing it little by little. Here's the source code anyways:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
// Declaration of constants
const char PlayerX = 'X';
const char PlayerO = 'O';

// Declaration of variables
char BoardSpaces[10] = {'0','1','2','3','4','5','6','7','8','9'};

char CurrentPlayer = 'X';

int Moves = '0';
int CMove = '0';
bool Win = false;

// Set up the board:
cout<<"\n\n "<<BoardSpaces[1]<<" | "<<BoardSpaces[2]<<" | "<<BoardSpaces[3]<<"\n";
cout<<" ---+---+---\n";
cout<<" "<<BoardSpaces[4]<<" | "<<BoardSpaces[5]<<" | "<<BoardSpaces[6]<<"\n";
cout<<" ---+---+---\n";
cout<<" "<<BoardSpaces[7]<<" | "<<BoardSpaces[8]<<" | "<<BoardSpaces[9]<<"\n\n";

while ( Win == false )
{
cout<<"Player "<<CurrentPlayer<<"'s turn: ";
cin>>CMove;
if ( CurrentPlayer == 'X' )
{
BoardSpaces[CMove] = CurrentPlayer;
CurrentPlayer = 'O';
cout<<"\n\n";
// Re-draw the board:
cout<<"\n\n "<<BoardSpaces[1]<<" | "<<BoardSpaces[2]<<" | "<<BoardSpaces[3]<<"\n";
cout<<" ---+---+---\n";
cout<<" "<<BoardSpaces[4]<<" | "<<BoardSpaces[5]<<" | "<<BoardSpaces[6]<<"\n";
cout<<" ---+---+---\n";
cout<<" "<<BoardSpaces[7]<<" | "<<BoardSpaces[8]<<" | "<<BoardSpaces[9]<<"\n\n";
Moves = Moves + 1;
if ( Moves <= 8 )
{
if ( BoardSpaces[1] == 'X' && BoardSpaces[2] == 'X' && BoardSpaces[3] == 'X' )
{
Win = true;
}
if ( BoardSpaces[1] == 'X' && BoardSpaces[4] == 'X' && BoardSpaces[7] == 'X' )
{
Win = true;
}
if ( BoardSpaces[3] == 'X' && BoardSpaces[6] == 'X' && BoardSpaces[9] == 'X' )
{
Win = true;
}
if ( BoardSpaces[7] == 'X' && BoardSpaces[8] == 'X' && BoardSpaces[9] == 'X' )
{
Win = true;
}
if ( BoardSpaces[2] == 'X' && BoardSpaces[5] == 'X' && BoardSpaces[8] == 'X' )
{
Win = true;
}
if ( BoardSpaces[4] == 'X' && BoardSpaces[5] == 'X' && BoardSpaces[6] == 'X' )
{
Win = true;
}
if ( BoardSpaces[1] == 'X' && BoardSpaces[5] == 'X' && BoardSpaces[9] == 'X' )
{
Win = true;
}
if ( BoardSpaces[3] == 'X' && BoardSpaces[5] == 'X' && BoardSpaces[7] == 'X' )
{
Win = true;
}
else
{
cout<<"\n\nTie game; niether player won!";
Sleep(2000);
exit(1);
}
if ( CurrentPlayer == 'O' )
{
BoardSpaces[CMove] = CurrentPlayer;
CurrentPlayer = 'X';
cout<<"\n\n";
// Re-draw the board:
cout<<"\n\n "<<BoardSpaces[1]<<" | "<<BoardSpaces[2]<<" | "<<BoardSpaces[3]<<"\n";
cout<<" ---+---+---\n";
cout<<" "<<BoardSpaces[4]<<" | "<<BoardSpaces[5]<<" | "<<BoardSpaces[6]<<"\n";
cout<<" ---+---+---\n";
cout<<" "<<BoardSpaces[7]<<" | "<<BoardSpaces[8]<<" | "<<BoardSpaces[9]<<"\n\n";
Moves = Moves + 1;
if ( Moves <= 8 )
{

if ( BoardSpaces[1] == 'O' && BoardSpaces[2] == 'O' && BoardSpaces[3] == 'O' )
{
Win = true;
}
if ( BoardSpaces[1] == 'O' && BoardSpaces[4] == 'O' && BoardSpaces[7] == 'O' )
{
Win = true;
}
if ( BoardSpaces[3] == 'O' && BoardSpaces[6] == 'O' && BoardSpaces[9] == 'O' )
{
Win = true;
}
if ( BoardSpaces[7] == 'O' && BoardSpaces[8] == 'O' && BoardSpaces[9] == 'O' )
{
Win = true;
}
if ( BoardSpaces[2] == 'O' && BoardSpaces[5] == 'O' && BoardSpaces[8] == 'O' )
{
Win = true;
}
if ( BoardSpaces[4] == 'O' && BoardSpaces[5] == 'O' && BoardSpaces[6] == 'O' )
{
Win = true;
}
if ( BoardSpaces[1] == 'O' && BoardSpaces[5] == 'O' && BoardSpaces[9] == 'O' )
{
Win = true;
}
if ( BoardSpaces[3] == 'O' && BoardSpaces[5] == 'O' && BoardSpaces[7] == 'O' )
{
Win = true;
}
else
{
cout<<"\n\nTie game; niether player won!";
Sleep(2000);
exit(1);
}
}
}
}
cout<<"\n\n"<<CurrentPlayer<<" is the winner!";
cin.get();
}
}
}



Then I realized, I bit off more than I could chew.. :(

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by Promit
...by using structured exception handling...
Did you mean C++ exception handling? SEH is a Windows system functionality and Microsoft extension to C (via the __try, __except and __finally statements), and not applicable to any programmer who hopes to keep his code portable.

I know you know this, but your audience might not.


Yeah, I did mean C++ exception handling. Misspeak on my part.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!