Jump to content
  • Advertisement
Sign in to follow this  
lordoftools

Please Help!

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

BACKGROUND: I decided to make a dopewars like game as a means of learning C++ i was doing very well and had about 1000 lines of working code and then i continued to add the functions BuyingDrugs() and BuyDrugsMenu() and suddenly im getting and error long before those functions are ever called in the CityOperations() function which gets called in when choicing New Game in the main menu. I commented out the two functions and the error is still there. I can not find what i messed up everythign worked great up until last night. PLEASE HELP ME find the error! WHAT I CHANGED SINCE IT WORKED LAST: NOTE: Must use MFC in Shared DLL from the Project->Settings menu in MSVC++ Added #include <sstream> #include <string> #include <stdexcept> unline std::string stringify(double x); class BadConversion : public std::runtime_error For the int to string convertions. Added:
[source code=cpp]
void BuyingDrugs(string Drug, int Price)
{
	//Function level Declarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,					FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 						OPEN_EXISTING, 0, 0);

	int intAmt;
	intAmt=9999;
	
	while (intAmt*Price>profile.Cash)
	{
		//print menu
		system("cls");
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"How much "<<Drug<<" you want? ($"<<Price<<" each)"<<endl;
		cout<<"Quantity: ";
		cin>>intAmt;
	}

}

void BuyDrugsMenu()
{
	//Function level Declarations
	char chrChoice;	
	bool oneS=false, twoS=false, oneP=false, twoP=false, oneH=false, twoH=false;
	int intTemp[12];
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);

	system("cls");
	PrintStats();
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);

	for (i=0; i<=11; i++)
	{

		if (intDrugArray<=profile.Cash)
			goto SkipFor;

	}
	cout<<"Your broke! Go somewhere else or go sell some of your product to make up the $$$.\n";
	goto EndOfFunc;
SkipFor:

	//print menu options
	cout<<"So you wanta buy some dope? Here's your choices...\n\n";
InvalidChoice:
	for (i=0; i<=11; i++)
	{

		if (cstrDrugArray=="ACID")
		{
			cout<<"A. ACID - "<<intDrugArray<<endl;
			intTemp[1]=intDrugArray;
		}
		else if (cstrDrugArray=="COCAINE")
		{
			cout<<"C. COCAINE - "<<intDrugArray<<endl;
			intTemp[2]=intDrugArray;
		}
		else if (cstrDrugArray=="HASHISH")
		{
			cout<<"H. HASHISH - "<<intDrugArray<<endl;
			intTemp[3]=intDrugArray;
			oneH=true;
		}
		else if (cstrDrugArray=="HERION")
		{
			cout<<"H. HERION - "<<intDrugArray<<endl;
			intTemp[4]=intDrugArray;
			twoH=true;
		}
		else if (cstrDrugArray=="LUDES")
		{
			cout<<"L. LUDES - "<<intDrugArray<<endl;
			intTemp[5]=intDrugArray;
		}
		else if (cstrDrugArray=="MDA")
		{
			cout<<"M. MDA - "<<intDrugArray<<endl;
			intTemp[6]=intDrugArray;
		}
		else if (cstrDrugArray=="OPIUM")
		{
			cout<<"O. OPIUM - "<<intDrugArray<<endl;
			intTemp[7]=intDrugArray;
		}
		else if (cstrDrugArray=="PCP")
		{
			cout<<"P. PCP - "<<intDrugArray<<endl;
			intTemp[8]=intDrugArray;
			oneP=true;
		}
		else if (cstrDrugArray=="PEYOTE")
		{
			cout<<"P. PEYOTE - "<<intDrugArray<<endl;
			intTemp[9]=intDrugArray;
			twoP=true;
		}
		else if (cstrDrugArray=="SHROOMS")
		{
			cout<<"S. SHROOMS - "<<intDrugArray<<endl;
			intTemp[10]=intDrugArray;
			oneS=true;
		}
		else if (cstrDrugArray=="SPEED")
		{
			cout<<"S. SPEED - "<<intDrugArray<<endl;
			intTemp[11]=intDrugArray;
			twoS=true;
		}
		else if (cstrDrugArray=="WEED")
		{
				cout<<"W. WEED - "<<intDrugArray<<endl;
				intTemp[12]=intDrugArray;
		}

	}
	cout<<"Selection: ";
	cin>>chrChoice;

	//check for duplicate letters and proseed with purchase
	if (chrChoice=='A' || chrChoice=='a')
	{

		BuyingDrugs("ACID", intTemp[1]);

	}
	else if (chrChoice=='C' || chrChoice=='c')
	{

		BuyingDrugs("COCAINE", intTemp[2]);

	}
	//for duplicate H's
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==true && twoH==true))
	{

		

	}
	//for none duplicate
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==false || twoH==false))
	{

		//run for to see which H is in it

	}
	else if (chrChoice=='L' || chrChoice=='l')
	{

		BuyingDrugs("LUDES", intTemp[5]);

	}
	else if (chrChoice=='M' || chrChoice=='m')
	{

		BuyingDrugs("MDA", intTemp[6]);

	}
	else if (chrChoice=='O' || chrChoice=='o')
	{

		BuyingDrugs("OPIUM", intTemp[7]);

	}
	//for duplicate P's
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==true && twoP==true))
	{



	}
	//for none duplicate
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==false || twoP==false))
	{

		//run for to see which P is in it

	}
	//for duplicate S's
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==true && twoS==true))
	{



	}
	//for none duplicate
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==false || twoS==false))
	{

		//run for to see which S is in it

	}
	else if (chrChoice=='W' || chrChoice=='w')
	{

		BuyingDrugs("WEED", intTemp[12]);

	}
	else
	{
		system("cls");
		PrintStats();
		SetConsoleColors(hConsole, 10, 0);
		cout<<"Invalid selection please pick again...\n\n";
		goto InvalidChoice;

	}


EndOfFunc:
	//reverts colors back
	SetConsoleColors(hConsole, 15, 0);

}

(Both those functions are unfinished) When all of the above are commented the error still occurs. THE ACTUAL ERROR: I run it, enter 1 for New Game, enter any name, hit enter and the error appears. Debug Assertion Failed! Program C:\Blah\Blah\Drug Wars.exe File afx.inl Line 122 For info on assertion failers see Visual C++ asserts. Now the error said that Line 122 was important somehow but i don't think it's refering to in my .cpp file. I tracked down the exact location where the error apears and it's on line 234 the switch (intDrugArray) is starting the error, i tried replacing that variable and such but same error no matter what. THE PLEAD: I have put a lot of time and effort into this program due to the fact that a few days ago i knew none of the code within it. PLEASE help me fix this error i do not want to rewrite the prgm, i was stupid and did not hold backup versions of it and i would liek to know how to prevent these errors. WHOLE APPLICATION CODE:
[source code=cpp]
//for VC++
#include "stdafx.h"

//for strings
#include <cstring>
#include <string>

//for basic functions i.e. (cout,cin)
#include <iostream>
#include <afx.h>

//for file manipulation
#include <fstream>
#include <cstdlib>

//For getch()/getche()
#include <conio.h>

//For srand() and time()
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

//for the string convertions
#include <sstream>
#include <string>
#include <stdexcept>

using namespace std;

//Global Variable Declaration
struct USERDATA
{

	string Name, Gun, Location;
	int Cash, Debt, Bank, Hentchmen, Health, Space, Day;
	
};
struct LOCDATA
{

	CString Name;
	int Police, minDrugs, maxDrugs;

};
int i;
struct LOCDATA loc;
struct USERDATA profile;
enum Drugs {ACID=1, COCAINE, HASHISH, HERION, LUDES, MDA, OPIUM, PCP, PEYOTE, SHROOMS, SPEED, WEED};
enum LOCS {BRONX=1, GHETTO, CENTRALPARK, MANHATTAN, CONEYISLAND, BROOKLYN, QUEENS, STATENISLAND};
WORD wText, 
     wBkg, 
     wOldColors;
int intDrugArray[12];
CString cstrDrugArray[12];
int intInvArray[250];
CString cstrInvArray[250];

//function delcarations
WORD SetConsoleColors(HANDLE hConsole, WORD wColorText, WORD wColorBkg);
WORD GetConsoleColors(HANDLE hConsole);
wstring get_module_path_wide(void);
string wsts(const wstring &src_string);
int MainMenu();
CString ProfileMenu();
inline std::string stringify(double x);
string BufferStr(string strString, int MAX_LEN);
void BuyingDrugs(string Drug, int Price);
void PrintStats();
void CityOperations(bool NewDay);
void BankMenu();
void SellDrugsMenu();
void BuyDrugsMenu();
void ChangeLocMenu();
void LoanSharkMenu();
void SaveGame();

//Start off function
int main(int argc, char* argv[])
{

	//Color change sample: (ranges 0-15) [uncommented part fo global variable declare]
		/*wText = 1; 
		wBkg = 5; 
		wOldColors;
		HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
		wOldColors = SetConsoleColors(hConsole, wText, wBkg);
		cout << "Colors in the console!" << endl << endl;
		SetConsoleColors(hConsole, wOldColors, 0);*/

	//Initialize random generator 
	srand ( time(NULL) );

	//Initialize global variables
	intInvArray[250]=0;

	//Function level Delcarations
	CString cstrProfile;
	string strTemp;
	int intMnuOpt;

	//Displays Main Menu
	intMnuOpt=MainMenu();

	//ERROR code
	if (intMnuOpt==0)
	{
		system("cls");
		cout<<"int MainMenu() returned ERROR code '0'\n";
	}

	//New Game code
	if (intMnuOpt==1)
	{
		//Variable initalization. 
		profile.Bank=0;
		profile.Health=100;
		profile.Day=1;
		profile.Cash=rand()%3000 + 2000;
		profile.Debt=rand()%9000 + 1000;
		profile.Gun="NONE";
		profile.Location="BRONX";
		profile.Hentchmen=rand()%4 + 7;
		profile.Space=profile.Hentchmen * 10;
		loc.maxDrugs=12;

		//Set user name.
		system("cls");
		cout<<"Enter your name: ";
		cin>>strTemp;
		profile.Name=strTemp.c_str();
		
		//Starts off in BRONX
		loc.Name="BRONX";
		loc.minDrugs=7;
		loc.Police=10;
		CityOperations(false);

	}

	//Load Profile code
	if (intMnuOpt==2)
	{
		//displays menu, prompts profile choice, stores the user ID
		cstrProfile=ProfileMenu();

		//ERROR checking
		if (cstrProfile=="NULL")
		{
			system("cls");
			cout<<"CString ProfileMenu() returned ERROR code 'NULL'\n";
		}

		//Profile Contence:
		//User Name, $$$, amount of items, rep points,  location
		//use ascii values of each digit to prevent easy editing

		//temp debugger code
		system("cls");
		printf("Profile: "); printf(cstrProfile); printf(" was selected.\n");

	}

	//Quit Code
	if (intMnuOpt==3)
	{
		system("cls");
		cout<<"Thank you for playing \"Drug Wars\" -- By: Derik Hammer.";
		getch();
		return 0;
	}

	//Application Terminator
	return 0;
}

//Operates the features of this location
void CityOperations(bool NewDay)
{
	
	if (NewDay==true)
	{
		//increase the day
		profile.Day++;

		//increase debt due to interest
		if (profile.Day%7==0)
			profile.Debt=profile.Debt+(profile.Debt*.12);

	}

	system("cls");
	PrintStats();

	//sets up the drugs which are in this city (price, how many, what kind)
	int intTemp, cnt=0, DrugChecker;
	bool PickAgain;
	int intChoice;
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	
	intTemp=rand()%(loc.maxDrugs-loc.minDrugs)+loc.minDrugs;

	while (intTemp-1>=cnt)
	{

		do 
		{
			PickAgain=false;
			DrugChecker=rand()%12+1;
			for (i=0; i<=11; i++)
			{
				if (intDrugArray==DrugChecker)
					PickAgain=true;
			}
		}
		while (PickAgain==true);
		intDrugArray[cnt]=DrugChecker;
		cnt++;

	};

	for (i=intTemp; i<=11; i++)
		intDrugArray=0;

	//Converts the int array to a string with the drug names and then makes the int array
	//into the prices array at the same time.
	for (i=0; i<=11; i++)
	{

		switch (intDrugArray)
		{	

			case ACID:
				cstrDrugArray="ACID";
				intDrugArray=rand()%3400+1000;
				break;

			case COCAINE:
				cstrDrugArray="COCAINE";
				intDrugArray=rand()%14000+15000;
				break;

			case HASHISH:
				cstrDrugArray="HASHISH";
				intDrugArray=rand()%800+480;
				break;

			case HERION:
				cstrDrugArray="HERION";
				intDrugArray=rand()%7500+5500;
				break;

			case LUDES:
				cstrDrugArray="LUDES";
				intDrugArray=rand()%49+11;
				break;

			case MDA:
				cstrDrugArray="MDA (Ecstasy)";
				intDrugArray=rand()%2900+1500;
				break;

			case OPIUM:
				cstrDrugArray="OPIUM";
				intDrugArray=rand()%710+540;
				break;

			case PCP:
				cstrDrugArray="PCP";
				intDrugArray=rand()%1500+1000;
				break;

			case PEYOTE:
				cstrDrugArray="PEYOTE";
				intDrugArray=rand()%480+220;
				break;

			case SHROOMS:
				cstrDrugArray="SHROOMS";
				intDrugArray=rand()%670+630;
				break;

			case SPEED:
				cstrDrugArray="SPEED";
				intDrugArray=rand()%160+90;
				break;

			case WEED:
				cstrDrugArray="WEED";
				intDrugArray=rand()%575+315;
				break;

			default:
				cstrDrugArray="ERROR: NO_DRUG";
				break;
		}	

	}

	//Run cops coding here, seperate function for the battle run only option when un-armed
	if (NewDay==true)
	{



	}

	//print city menu
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);

	cout<<"Welcome to "; printf(loc.Name); cout<<"!\n";
	
	//if its the home city [BRONX] then display spec menu
	if (loc.Name=="BRONX")
	{

specPickAgain:
		cout<<"1. Check out available Drugs.\n";
		cout<<"2. Sell Drugs.\n";
		cout<<"3. Change location.\n";
		cout<<"4. Visit Bank.\n";
		cout<<"5. Visit Loan Shark.\n";
		cout<<"6. Save Game.\n";
		cout<<"Selection: ";
		//await choice
		cin>>intChoice;

		switch (intChoice)
		{

		case 1:
			BuyDrugsMenu();
			break;

		case 2:
			SellDrugsMenu();
			break;

		case 3:
			ChangeLocMenu();
			break;

		case 4:
			BankMenu();
			break;

		case 5:
			LoanSharkMenu();
			break;

		case 6:
			SaveGame();
			break;

		default:
			goto specPickAgain;
			break;

		}

	}
	else
	{

normPickAgain:
		cout<<"1. Check out available Drugs.\n";
		cout<<"2. Sell Drugs.\n";
		cout<<"3. Change location.\n";
		cout<<"Selection: ";
		//await choice
		cin>>intChoice;

		switch (intChoice)
		{

		case 1:
			BuyDrugsMenu();
			break;

		case 2:
			SellDrugsMenu();
			break;

		case 3:
			ChangeLocMenu();
			break;

		default:
			system("cls");
			PrintStats();
			//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
			SetConsoleColors(hConsole, 10, 0);
			cout<<"Invalid choice, please pick again.\n";
			goto normPickAgain;
			break;

		}
	}

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);

}

void BankMenu()
{

	//function level delcarations
	char chrChoice;
	int intAmt;
	bool boolDep=false, boolWithd=false;

	//reset screen and disp stats again
	system("cls");
	PrintStats();

	//print bank options
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	SetConsoleColors(hConsole, 10, 0);

	cout<<"Welcome to the Bank!\n\n";

	//check to see what he can do in the bank
	if (profile.Cash>0)
	{
		cout<<"D. Deposit (Up to $"<<profile.Cash<<")\n";
		boolDep=true;
	}
	if (profile.Bank>0)
	{
		cout<<"W. Withdraw (Up to $"<<profile.Bank<<")\n";
		boolWithd=true;
	}
	cout<<"L. Leave Bank.\n";	
	//await choice
	cout<<"Selection: ";
	cin>>chrChoice;

	if ((chrChoice=='d' || chrChoice=='D') && boolDep==true)
	{

		//disp deposit menu
		system("cls");
		PrintStats();
		SetConsoleColors(hConsole, 10, 0);
DepAgain:
		cout<<"Bank Deposit -- $"<<profile.Cash<<" available.\n\n";
		cout<<"Deposit Amount (0 to cancel): ";
		//await choice
		cin>>intAmt;
		if (intAmt>profile.Cash || intAmt<0)
		{
			system("cls");
			PrintStats();
			SetConsoleColors(hConsole, 10, 0);
			cout<<"Invalid $ amount please pick again.\n\n";
			goto DepAgain;
		}
		//alter $ amounts accordingly
		profile.Cash=profile.Cash-intAmt;
		profile.Bank=profile.Bank+intAmt;


	}
	else if ((chrChoice=='w' || chrChoice=='W') && boolWithd==true)
	{

		//disp withdraw menu
		system("cls");
		PrintStats();
		SetConsoleColors(hConsole, 10, 0);
WDrawAgain:
		cout<<"Bank Withdraw -- $"<<profile.Bank<<" available.\n\n";
		cout<<"Withdraw Amount (0 to cancel): ";
		//await choice
		cin>>intAmt;
		if (intAmt>profile.Bank || intAmt<0)
		{
			system("cls");
			PrintStats();
			SetConsoleColors(hConsole, 10, 0);
			cout<<"Invalid $ amount please pick again.\n\n";
			goto WDrawAgain;
		}
		//alter $ amounts accordingly
		profile.Bank=profile.Bank-intAmt;
		profile.Cash=profile.Cash+intAmt;

	}
	else if (chrChoice=='l' || chrChoice=='L')
	{

		//return to your city
		CityOperations(false);

	}
	else
		BankMenu();

	CityOperations(false);

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);

}
void SellDrugsMenu()
{

	//debugger code
	cout<<"debugger code: in void SellDrugsMenu()\n";

}

void BuyingDrugs(string Drug, int Price)
{
	//Function level Declarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	int intAmt;
	intAmt=9999;
	
	while (intAmt*Price>profile.Cash)
	{
		//print menu
		system("cls");
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"How much "<<Drug<<" you want? ($"<<Price<<" each)"<<endl;
		cout<<"Quantity: ";
		cin>>intAmt;
	}

}

void BuyDrugsMenu()
{
	//Function level Declarations
	char chrChoice;	
	bool oneS=false, twoS=false, oneP=false, twoP=false, oneH=false, twoH=false;
	int intTemp[12];
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);

	system("cls");
	PrintStats();
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);

	for (i=0; i<=11; i++)
	{

		if (intDrugArray<=profile.Cash)
			goto SkipFor;

	}
	cout<<"Your broke! Go somewhere else or go sell some of your product to make up the $$$.\n";
	goto EndOfFunc;
SkipFor:

	//print menu options
	cout<<"So you wanta buy some dope? Here's your choices...\n\n";
InvalidChoice:
	for (i=0; i<=11; i++)
	{

		if (cstrDrugArray=="ACID")
		{
			cout<<"A. ACID - "<<intDrugArray<<endl;
			intTemp[1]=intDrugArray;
		}
		else if (cstrDrugArray=="COCAINE")
		{
			cout<<"C. COCAINE - "<<intDrugArray<<endl;
			intTemp[2]=intDrugArray;
		}
		else if (cstrDrugArray=="HASHISH")
		{
			cout<<"H. HASHISH - "<<intDrugArray<<endl;
			intTemp[3]=intDrugArray;
			oneH=true;
		}
		else if (cstrDrugArray=="HERION")
		{
			cout<<"H. HERION - "<<intDrugArray<<endl;
			intTemp[4]=intDrugArray;
			twoH=true;
		}
		else if (cstrDrugArray=="LUDES")
		{
			cout<<"L. LUDES - "<<intDrugArray<<endl;
			intTemp[5]=intDrugArray;
		}
		else if (cstrDrugArray=="MDA")
		{
			cout<<"M. MDA - "<<intDrugArray<<endl;
			intTemp[6]=intDrugArray;
		}
		else if (cstrDrugArray=="OPIUM")
		{
			cout<<"O. OPIUM - "<<intDrugArray<<endl;
			intTemp[7]=intDrugArray;
		}
		else if (cstrDrugArray=="PCP")
		{
			cout<<"P. PCP - "<<intDrugArray<<endl;
			intTemp[8]=intDrugArray;
			oneP=true;
		}
		else if (cstrDrugArray=="PEYOTE")
		{
			cout<<"P. PEYOTE - "<<intDrugArray<<endl;
			intTemp[9]=intDrugArray;
			twoP=true;
		}
		else if (cstrDrugArray=="SHROOMS")
		{
			cout<<"S. SHROOMS - "<<intDrugArray<<endl;
			intTemp[10]=intDrugArray;
			oneS=true;
		}
		else if (cstrDrugArray=="SPEED")
		{
			cout<<"S. SPEED - "<<intDrugArray<<endl;
			intTemp[11]=intDrugArray;
			twoS=true;
		}
		else if (cstrDrugArray=="WEED")
		{
				cout<<"W. WEED - "<<intDrugArray<<endl;
				intTemp[12]=intDrugArray;
		}

	}
	cout<<"Selection: ";
	cin>>chrChoice;

	//check for duplicate letters and proseed with purchase
	if (chrChoice=='A' || chrChoice=='a')
	{

		BuyingDrugs("ACID", intTemp[1]);

	}
	else if (chrChoice=='C' || chrChoice=='c')
	{

		BuyingDrugs("COCAINE", intTemp[2]);

	}
	//for duplicate H's
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==true && twoH==true))
	{

		

	}
	//for none duplicate
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==false || twoH==false))
	{

		//run for to see which H is in it

	}
	else if (chrChoice=='L' || chrChoice=='l')
	{

		BuyingDrugs("LUDES", intTemp[5]);

	}
	else if (chrChoice=='M' || chrChoice=='m')
	{

		BuyingDrugs("MDA", intTemp[6]);

	}
	else if (chrChoice=='O' || chrChoice=='o')
	{

		BuyingDrugs("OPIUM", intTemp[7]);

	}
	//for duplicate P's
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==true && twoP==true))
	{



	}
	//for none duplicate
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==false || twoP==false))
	{

		//run for to see which P is in it

	}
	//for duplicate S's
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==true && twoS==true))
	{



	}
	//for none duplicate
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==false || twoS==false))
	{

		//run for to see which S is in it

	}
	else if (chrChoice=='W' || chrChoice=='w')
	{

		BuyingDrugs("WEED", intTemp[12]);

	}
	else
	{
		system("cls");
		PrintStats();
		SetConsoleColors(hConsole, 10, 0);
		cout<<"Invalid selection please pick again...\n\n";
		goto InvalidChoice;

	}


EndOfFunc:
	//reverts colors back
	SetConsoleColors(hConsole, 15, 0);

}
void ChangeLocMenu()
{
	//Function level Declarations
	int intChoice;	
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);

	system("cls");
	PrintStats();
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);
LocPickAgain:
	cout<<"Where would you like to go?\n\n";
	cout<<"1. BRONX\n";
	cout<<"2. GHETTO\n";
	cout<<"3. CENTRAL PARK\n";
	cout<<"4. MANHATTAN\n";
	cout<<"5. CONEY ISLAND\n";
	cout<<"6. BROOKLYN\n";
	cout<<"7. QUEENS\n";
	cout<<"8. STATEN ISLAND\n";
	cout<<"9. Back to "; printf(loc.Name); cout<<"\n";
	cout<<"Selection: ";
	//await selection
	cin>>intChoice;

	switch (intChoice)
	{

	case BRONX:
		if (profile.Location=="BRONX")
			intChoice=9;
		profile.Location="BRONX";
		loc.Name="BRONX";
		loc.minDrugs=7;
		loc.maxDrugs=12;
		loc.Police=10;
		break;

	case GHETTO:
		if (profile.Location=="GHETTO")
			intChoice=9;
		profile.Location="GHETTO";
		loc.Name="GHETTO";
		loc.minDrugs=8;
		loc.maxDrugs=12;
		loc.Police=5;
		break;

	case CENTRALPARK:
		if (profile.Location=="CENTRALPARK")
			intChoice=9;
		profile.Location="CENTRALPARK";
		loc.Name="CENTRAL PARK";
		loc.minDrugs=6;
		loc.maxDrugs=12;
		loc.Police=15;
		break;

	case MANHATTAN:
		if (profile.Location=="MANHATTAN")
			intChoice=9;
		profile.Location="MANHATTAN";
		loc.Name="MANHATTAN";
		loc.minDrugs=4;
		loc.maxDrugs=12;
		loc.Police=80;
		break;

	case CONEYISLAND:
		if (profile.Location=="CONEYISLAND")
			intChoice=9;
		profile.Location="CONEYISLAND";
		loc.Name="CONEY ISLAND";
		loc.minDrugs=6;
		loc.maxDrugs=12;
		loc.Police=20;
		break;

	case BROOKLYN:
		if (profile.Location=="BROOKLYN")
			intChoice=9;
		profile.Location="BROOKLYN";
		loc.Name="BROOKLYN";
		loc.minDrugs=4;
		loc.maxDrugs=12;
		loc.Police=70;
		break;

	case QUEENS:
		if (profile.Location=="QUEENS")
			intChoice=9;
		profile.Location="QUEENS";
		loc.Name="QUEENS";
		loc.minDrugs=6;
		loc.maxDrugs=12;
		loc.Police=50;
		break;

	case STATENISLAND:
		if (profile.Location=="STATENISLAND")
			intChoice=9;
		profile.Location="STATENISLAND";
		loc.Name="STATEN ISLAND";
		loc.minDrugs=6;
		loc.maxDrugs=12;
		loc.Police=20;
		break;

	case 9:
		break;

	default: 
		system("cls"); 
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"Invalid entry please pick again.\n\n";
		goto LocPickAgain;
		break;

	}

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);

	//if the city never changes then don't penalize with a new day
	if (intChoice==9)
	{
		CityOperations(false);
	}
	else
	{
		CityOperations(true);
	}

}
void LoanSharkMenu()
{
	//Function level Declarations
	int intChoice, intAmt;
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);

LoanChoiceAgain:

	//Prints the loan shark welcome msg
	system("cls");
	PrintStats();
	SetConsoleColors(hConsole, 10, 0);
	cout<<"Welcome to Shady Shawn's Shack!\n";
	cout<<"Rates are currently at 12% factored in each Sunday (7th day).\n\n";
	
	//allows you to pay off debt only when you have some
	if(profile.Debt>0)
	{
		//prints menu
		cout<<"1. Pay off debt.\n";
		cout<<"2. Leave Shady Shawn's.\n";
		cout<<"Selection: ";
		//await choice
		cin>>intChoice;

		switch (intChoice)
		{

		//run through pay off options/operations
		case 1:
			system("cls");
			PrintStats();
			SetConsoleColors(hConsole, 10, 0);
PLoanAgain:
			cout<<"Shady Shawn's Shack!\n\n";
			cout<<"Enter Amount to Pay off (0 to cancel): ";
			cin>>intAmt;
			if (intAmt>profile.Cash || intAmt<0)
			{
				system("cls");
				PrintStats();
				SetConsoleColors(hConsole, 10, 0);
				cout<<"Invalid $ amount please pick again.\n\n";
				goto PLoanAgain;
			}

			//redefines variables appropriatly
			profile.Cash=profile.Cash-intAmt;
			profile.Debt=profile.Debt-intAmt;

			break;

		//leaves the loan shark and heads back to the city without a day increase
		case 2:
			CityOperations(false);
			break;

		//sends you back to pick again due to invalid entry
		default:
			goto LoanChoiceAgain;
			break;

		}
	}
	else
	{
		//allows you to take out a loan when you have no debt
		cout<<"1. Take out a Loan.\n";
		cout<<"2. Leave Shady Shawn's.\n";
		cout<<"Selection: ";
		//await choice
		cin>>intChoice;

		switch (intChoice)
		{

		//prints options and runs the loan request operations
		case 1:
			system("cls");
			PrintStats();
			SetConsoleColors(hConsole, 10, 0);
PLoanAgain2:
			cout<<"Shady Shawn's Shack!\n\n";
			cout<<"Enter Amount of the Loan (0 to cancel): ";
			//await selection
			cin>>intAmt;

			//can't use negatives
			if (intAmt<0)
			{
				system("cls");
				PrintStats();
				SetConsoleColors(hConsole, 10, 0);
				cout<<"Invalid amount entered, try again man.\n\n";
				goto PLoanAgain2;
			}
			//only loans out up to 30000
			if (intAmt>=30000)
			{
				system("cls");
				PrintStats();
				SetConsoleColors(hConsole, 10, 0);
				cout<<"I only give out Loans of $30,000 and below, try again man.\n\n";
				goto PLoanAgain2;
			}

			//redefines variables appropriatly
			profile.Cash=profile.Cash+intAmt;
			profile.Debt=profile.Debt+intAmt;

			break;

		//send you back to the city without a day penalty
		case 2:
			CityOperations(false);
			break;

		//sends user through menu again due to invalid entry
		default:
			goto LoanChoiceAgain;
			break;

		}

	}

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);

	//sends user back to the city without day penalty
	CityOperations(false);

}
void SaveGame()
{

	//debugger code
	cout<<"debugger code: in void SaveGame()\n";

}
 
 //this class checks for bad convertions with stringify(int x)
 class BadConversion : public std::runtime_error 
 {
 public:
   BadConversion(const std::string& s)
     : std::runtime_error(s)
     { }
 };
 
 //converts ints into strings
 inline std::string stringify(int x)
 {
   std::ostringstream o;
   if (!(o << x))
     throw BadConversion("stringify(double)");
   return o.str();
 }

//Prints the user data on the screen
void PrintStats()
{
	//Function level Declarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	string st;

	//make stats 'YELLOW' (14) with 'blk bg' (0) [stats std color]
	SetConsoleColors(hConsole, 14, 0);
    
	//print stats
	system("cls");
	cout<<BufferStr("[" + profile.Name + "]",20)<<"Location: "<<profile.Location<<"\n";

	st="Cash: " + stringify(profile.Cash);
	cout<<BufferStr(st,20)<<"Debt: "<<profile.Debt<<"\n";

	st="Bank: " + stringify(profile.Bank);
	cout<<BufferStr(st,20)<<"Hentchmen: "<<profile.Hentchmen<<"\n";

	st="Health: " + stringify(profile.Health);
	cout<<BufferStr(st,20)<<"Free Space: "<<profile.Space<<"\n";

	cout<<BufferStr("Gun: " + profile.Gun,20)<<"Day: "<<profile.Day<<"\n\n";

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);

}

//Fixes text into columns
string BufferStr(string strString, int MAX_LEN)
{
	//Function level delcarations
	int intSpaces;
	string strTemp;
	
	//add proper spaces after the string
	intSpaces=MAX_LEN-strString.length();
	strTemp=strString;
	for (i=1; i<=intSpaces; i++)
	{
		strTemp=strTemp + " ";
	}

	//return new str
	return (strTemp.c_str());

}

//Displays the profiles menu along with scanning the app's dir for the
//profile files within it.
CString ProfileMenu()
{

	//Function level Declarations
	CString Profile1, Profile2, Profile3, Profile4, Profile5;
	CString cstrPath;
	int intChoice;
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	
	//Stores application's directory location
	cstrPath=wsts(get_module_path_wide()).c_str();

	//insert directory scanning, list creation, and extention trimming here and delete the following
	Profile1="Derik";
	Profile2="Dennis";
	Profile3="Dad";
	Profile4="Jen";
	Profile5="Meem";

	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);

	//Print menu
	system("cls");
	cout<<"Drug Wars --- By: Derik Hammer\n\n";
	printf("1. "); printf(Profile1); printf("\n");
	printf("2. "); printf(Profile2); printf("\n");
	printf("3. "); printf(Profile3); printf("\n");
	printf("4. "); printf(Profile4); printf("\n");
	printf("5. "); printf(Profile5); printf("\n\n");
	cout<<"Selection: ";
	//Await choice
	cin>>intChoice;

	//loops if invalid numbers are entered.
	while (intChoice<1 || intChoice>5)
	{
	
		SetConsoleColors(hConsole, 10, 0);
		//Print menu
		system("cls");
		cout<<"Drug Wars --- By: Derik Hammer\n\n";
		printf("1. "); printf(Profile1); printf("\n");
		printf("2. "); printf(Profile2); printf("\n");
		printf("3. "); printf(Profile3); printf("\n");
		printf("4. "); printf(Profile4); printf("\n");
		printf("5. "); printf(Profile5); printf("\n\n");
		cout<<"INVALID SELECTION PLEASE CHOOSE AGAIN!\n";
		cout<<"Selection: ";
		//Await choice
		cin>>intChoice;
	}

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);
	
	//Returns the name of the profile needed to be used
	switch (intChoice)
	{

		case 1:
			return Profile1;
			break;

		case 2:
			return Profile2;
			break;

		case 3:
			return Profile3;
			break;

		case 4:
			return Profile4;
			break;

		case 5:
			return Profile5;
			break;

	}

	return "NULL";
}

//Displays the options for the Main Menu
int MainMenu()
{
	//Function level Declarations
	char chrChoice;
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);

	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);

	//Print menu
	cout<<"Drug Wars --- By: Derik Hammer\n\n";
	cout<<"1. New Game.\n";
	cout<<"2. Load Profile.\n";
	cout<<"3. Quit.\n\n";
	cout<<"Selection: ";
	//Await choice
	cin>>chrChoice;
	
CheckAgain:
	switch (chrChoice)
	{

	//Proceed with new game
	case '1':
		//revert to old colors
		SetConsoleColors(hConsole, 15, 0);
		return (1);
		break;

	//Proceed with loading profile menu
	case '2':
		//revert to old colors
		SetConsoleColors(hConsole, 15, 0);
		return (2);
		break;

	//Proceed with exiting the application
	case '3':
		//revert to old colors
		SetConsoleColors(hConsole, 15, 0);
		return (3);
		break;

	//Clear screen, reprint menu, notify invalid selection, and allow a second choice
	default:
		system("cls");
		cout<<"Drug Wars --- By: Derik Hammer\n\n";
		cout<<"1. New Game.\n";
		cout<<"2. Load Profile.\n";
		cout<<"3. Quit.\n\n";
		//revert to old colors
		SetConsoleColors(hConsole, 1, 0);
		cout<<"INVALID SELECTION PLEASE CHOOSE AGAIN!\n";
		cout<<"Selection: ";
		cin>>chrChoice;
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		goto CheckAgain;

	}

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);

	return(0);

}

// use Unicode (wide) version of GetModuleFileName
wstring get_module_path_wide(void)
{
	wchar_t wide_buf[65536];
	wstring module_name;

	if(!GetModuleFileNameW(GetModuleHandle(0), wide_buf, 65535))
		return module_name;

	wide_buf[65535] = L'\0';

	module_name = wide_buf;

	size_t pos = module_name.find_last_of(L'\\');

	if(pos != string::npos)
		module_name = module_name.substr(0, pos);

	return module_name;
}

// use this function to convert from wide wstring to ASCII string if need be
string wsts(const wstring &src_string)
{
	size_t src_len = src_string.length();

	if(src_len == 0)
		return "";

	char *buf = new(std::nothrow) char[src_len + 1];

	if(buf == 0)
		return "";

	wcstombs(buf, src_string.c_str(), src_len);
	buf[src_len] = '\0';

	string final_string = buf;

	if(buf != 0)
		delete [] buf;

	return final_string;
}

//Color Change functions
WORD GetConsoleColors(HANDLE hConsole)
{
    // get current console text attributes
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    return csbi.wAttributes;
}

WORD SetConsoleColors(HANDLE hConsole, WORD wColorText, WORD wColorBkg = 0)
{
    // get old text attributes
    WORD wOldColors = GetConsoleColors(hConsole);

    // set new text attributes
    SetConsoleTextAttribute(hConsole, wColorText | (wColorBkg << 4));
    return wOldColors;
}

Share this post


Link to post
Share on other sites
Advertisement
firstly Im guessing you are using Visual C++ 6.0? As your program works perfectly fine on .net 2003 but crashed as you decribed when I ran it through my 6.0 install.

Anyway your problem seems to be with templates. Visual Studio 6.0 template support is a bit crap really.

Anyway replace all your CStrings with std::string seems to fix your problem nicely. Remember in your printfs you'll need to string.c_str() :)

Share this post


Link to post
Share on other sites
Thank you very much, a friend of mine who is an amazing BASIC programmer (all verions of BASIC-Visual BASIC) did some C++ work and told me that CString was the standard and that i should not use string because it's something that had unpredicatable effects and such. Apparently i should leave the VB to him and the C++ to you guys. Thank you so much i love this forum and all the people who post on it.

WORKED GREAT! A+++
-Lordoftools

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!