Jump to content
  • Advertisement

Archived

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

rancid23

abnormal program termination

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

Hi, I''ve been programming in c++ for about a week now. I''m using Visual C++ 6.0 and am writing my first text adventure game. For some reason my program (seemingly randomly) spits out "abnormal program termination" and quits. What does this mean, and why does it do it? Below is the source code:
#include <iostream>								
#include<string>
using namespace std;

int doroom(int useroom);
void look(int uroom);
void donpc(int usroom, string szUc);


string szRoomdescription[100];
int gamecounter = 0;
int npclocation[30];
string npcshortdescription[30];
string npclongdescription[30];
string npcname[30];
int functioncounter = 0;

int main()							
{														
	
	int userroom = 1;
	
	// beginning of room and NPC descriptions

	szRoomdescription[1] = "You are at the south gate. The gate is closed. The road continues to the <north>";
	szRoomdescription[2] = "You are on the main road in a bustling city. The road goes <north> and <south>";
	szRoomdescription[3] = "You are in the center of a crowded market. Roads head to the <east>, <west>, and <south>.";
	szRoomdescription[4] = "The road ends here. There is an armory to the <north>. The road continues to the <east>.";
	szRoomdescription[5] = "You are at the west gate. The gate is closed. The road continues to the <east>.";
	szRoomdescription[6] = "You are in a cluttered armory. Weapons and shields line the walls. There is a door to the <south>.";

	npcname[1] = "guard";
	npclocation[1] = 1;
	npcshortdescription[1] = "A <guard> is here.";
	npclongdescription[1] = "The guard looks nervous.";
	npcname[2] = "guard";
	npclocation[2] = 5;
	npcshortdescription[2] = "A <guard> is here.";
	npclongdescription[2] = "The guard looks nervous.";
	npcname[3] = "Gruff";
	npclocation[3] = 6;
	npcshortdescription[3] = "<Gruff> the armorer smiles at you warmly.";
	npclongdescription[3] = "The shopkeeper seems happy to have someone in his store.";

	// end of room and NPC descriptions

	
	
	gamecounter = 0;

	
	

	
	userroom = 1;

	look(userroom);
	
	//Main game loop

	while (gamecounter!=1)
	{
	

	userroom = doroom(userroom);
	
	
	
	}
	return 0;

}


void look(int uroom)
{
	cout << szRoomdescription[uroom] << endl;
	functioncounter=0;
	while(functioncounter<30)
	{
	functioncounter++;
	if(npclocation[functioncounter]==uroom)
	{cout << npcshortdescription[functioncounter];}
	}
	cout << endl;
}

int doroom(int useroom)
{
	string szUsercommand = "blah";
	//user prompt

	getline(cin, szUsercommand);
	
	
	//room 1

	if(useroom == 1)
	{
		if(szUsercommand == "north")
		{
			useroom = 2;
			look(useroom);
		}
	
		if(szUsercommand == "south")
		{
			cout << "The gate is closed." << endl;
		}
	
	
		if(szUsercommand == "west")
		{
			cout << "You can''t go that way." << endl;
		}
	
		if(szUsercommand == "east")
		{
			cout << "You can''t go that way." << endl;
		}
	}
	else	//room 2

	if(useroom == 2)
	{
		if(szUsercommand == "south")
		{
			useroom = 1;
			look(useroom);
		}
	
    
		if(szUsercommand == "west")
		{
			cout << "You can''t go that way." << endl;
		}
	
		if(szUsercommand == "east")
		{
			cout << "You can''t go that way." << endl;
		}
		
		if(szUsercommand == "north")
		{
			useroom = 3;
			look(useroom);
		}
	}
	else
	//room 3

	if(useroom == 3)
	{
		if(szUsercommand == "south")
		{
			useroom = 2;
			look(useroom);
		}
	
		if(szUsercommand == "west")
		{
			useroom = 5;
			look(useroom);
		}

		if(szUsercommand == "east")
		{
			useroom = 4;
			look(useroom);
		}
		
		if(szUsercommand == "north")
		{
			cout << "You can''t go that way." << endl;
		}
	}
	else	//room 4

	if(useroom == 4)
	{
		if(szUsercommand == "south")
		{
			cout << "You can''t go that way." << endl;
		}

		if(szUsercommand == "east")
		{
			cout << "You can''t go that way." << endl;
		}
		if(szUsercommand == "west")
		{
			useroom = 3;
			look(useroom);
		}
		if(szUsercommand == "north")
		{
			useroom = 6;
			look(useroom);
		}
	}
	else	//room 5

	if(useroom == 5)
	{
		if(szUsercommand == "south")
		{
			cout << "You can''t go that way." << endl;
		}
		if(szUsercommand == "north")
		{
			cout << "You can''t go that way." << endl;
		}
		if(szUsercommand == "east")
		{
			cout << "The gate is closed." << endl;
		}
		if(szUsercommand == "west")
		{
			useroom = 3;
			look(useroom);
		}
	}
	else	//room 6

	if(useroom == 6)
	{
		if(szUsercommand == "south")
		{
			useroom = 4;
			look(useroom);
			
		}
		if(szUsercommand == "north")
		{
			cout << "You can''t go that way." << endl;
		}
		if(szUsercommand == "east")
		{
			cout << "You can''t go that way." << endl;
		}
		if(szUsercommand == "west")
		{
			cout << "You can''t go that way." << endl;
		}
	}

	if(szUsercommand == "quit")
	{
	 gamecounter=1;
	}
	
	if(szUsercommand == "look")
	{
	look(useroom);	
	}

	donpc(useroom, szUsercommand);

 return useroom;
}

void donpc(int usroom, string szUc)
{
	string commandmatchinsert;
	string commandmatch;
	functioncounter=0;
	while(functioncounter<30)
	{
	functioncounter++;
	if(npclocation[functioncounter]==usroom)
	{
		commandmatchinsert = npcname[functioncounter];
		commandmatch = "look ";
		commandmatch.insert(6, commandmatchinsert);
		if(commandmatch == szUc)
		{
			cout << npclongdescription[functioncounter] << endl;
		}
	}

	}
}

Share this post


Link to post
Share on other sites
Advertisement
this might not be it but try putting "functioncounter++;" behind

if(npclocation[functioncounter]==usroom)
{
commandmatchinsert = npcname[functioncounter];
commandmatch = "look ";
commandmatch.insert(6, commandmatchinsert);
if(commandmatch == szUc)
{
cout << npclongdescription[functioncounter] << endl;
}
}


[edited by - MonkeyInBlack on February 28, 2004 2:58:57 AM]

[edited by - MonkeyInBlack on February 28, 2004 2:59:52 AM]

Share this post


Link to post
Share on other sites

void donpc(int usroom, string szUc)
{
...
if(npclocation[functioncounter]==usroom)
{
commandmatchinsert = npcname[functioncounter];
commandmatch = "look ";
commandmatch.insert(6, commandmatchinsert); //<-- problem w/ this line
if(commandmatch == szUc)
{
cout << npclongdescription[functioncounter] << endl;
}
}
...
}


I think you mean commandmatch.insert(5, commandmatchinsert); Why not do something like this instead?


commandmatch.insert(commandmatch.size(), commandmatchinsert);
//or
commandmatch += commandmatchinsert;






--{You fight like a dairy farmer!}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!