Jump to content
  • Advertisement
Sign in to follow this  
lordoftools

menu issues

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

Ok guys i know i have posted a lot about this Drug Wars game but the reason is that it's a large project and it's my first C++ project. Maybe i shouldn't have started with something so big but with 3000 lines already written i refuse to give up on it. So that people don't get pissed off at my repeated posts im planning on posting my issues in small chunks which will help in 2 ways. First off, i hope it will show that my multiple threads are truely about different topics and not me repeatedly asking the same general question of "can someone find my bug". Second i hope it will increase the possibility of a fix because from my friends i talk to in person most of them didn't want to help me because of how large the project is and how difficult it would be to debug it as a whole. With all that said, the issue i'd wish to address is a menu i created and why it on occation refuses to let you select Drugs, (usually ACID, LUDES, COCAINE). Here's the code: didn't include the declared because i use prefixes on my variables for what type they are. (oneS, twoS, oneP, twoP, oneH, twoH are all bools).
[source code=cpp]
//print menu options
	cout<<"So you wanta buy some dope? Here's your choices...\n\n";
InvalidChoice:
	for (i=0; i<=11; i++)
	{
		if (strDrugArray=="ACID")
		{
			cout<<"A. ACID - $"<<intDrugArray<<endl;
			intTemp[1]=intDrugArray;
			boolDrugPresent[0]=true;
		}
		else if (strDrugArray=="COCAINE")
		{
			cout<<"C. COCAINE - $"<<intDrugArray<<endl;
			intTemp[2]=intDrugArray;
			boolDrugPresent[1]=true;
		}
		else if (strDrugArray=="HASHISH")
		{
			cout<<"H. HASHISH - $"<<intDrugArray<<endl;
			intTemp[3]=intDrugArray;
			oneH=true;
		}
		else if (strDrugArray=="HERION")
		{
			cout<<"H. HERION - $"<<intDrugArray<<endl;
			intTemp[4]=intDrugArray;
			twoH=true;
		}
		else if (strDrugArray=="LUDES")
		{
			cout<<"L. LUDES - $"<<intDrugArray<<endl;
			intTemp[5]=intDrugArray;
			boolDrugPresent[2]=true;
		}
		else if (strDrugArray=="MDA (Ecstasy)")
		{
			cout<<"M. MDA (Ecstasy) - $"<<intDrugArray<<endl;
			intTemp[6]=intDrugArray;
			boolDrugPresent[3]=true;
		}
		else if (strDrugArray=="OPIUM")
		{
			cout<<"O. OPIUM - $"<<intDrugArray<<endl;
			intTemp[7]=intDrugArray;
			boolDrugPresent[4]=true;
		}
		else if (strDrugArray=="PCP")
		{
			cout<<"P. PCP - $"<<intDrugArray<<endl;
			intTemp[8]=intDrugArray;
			oneP=true;
		}
		else if (strDrugArray=="PEYOTE")
		{
			cout<<"P. PEYOTE - $"<<intDrugArray<<endl;
			intTemp[9]=intDrugArray;
			twoP=true;
		}
		else if (strDrugArray=="SHROOMS")
		{
			cout<<"S. SHROOMS - $"<<intDrugArray<<endl;
			intTemp[10]=intDrugArray;
			oneS=true;
		}
		else if (strDrugArray=="SPEED")
		{
			cout<<"S. SPEED - $"<<intDrugArray<<endl;
			intTemp[11]=intDrugArray;
			twoS=true;
		}
		else if (strDrugArray=="WEED")
		{
			cout<<"W. WEED - $"<<intDrugArray<<endl;
			intTemp[12]=intDrugArray;
			boolDrugPresent[5]=true;
		}
	}

	//print gun options and determine price with trade-in value of old gun
	if (boolGun==true)
	{
		boolDrugPresent[6]=true;

		if (profile.Gun=="BARETTA")
			TradeIn=1500;
		if (profile.Gun==".38SPEC")
			TradeIn=1725;
		if (profile.Gun=="RUGER")
			TradeIn=1450;
		if (profile.Gun=="SATNIGHTSPEC")
			TradeIn=1600;
		if (profile.Gun=="NONE")
			TradeIn=0;

		switch (intGun)
		{
			case 1:
				cout<<"\nG. Baretta (Reduces police presence to 13%, Current Rating="<<20-profile.GunRate<<"%) - $3000."<<endl;
				cout<<"\t$"<<3000-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=3000-TradeIn;
				buyGun="Baretta";
				break;
			case 2:
				cout<<"\nG. .38 Special (Reduces police presence to 7%, Current Rating="<<20-profile.GunRate<<"%) - $3500."<<endl;
				cout<<"\t$"<<3500-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=3500-TradeIn;
				buyGun=".38 Special";
				break;
			case 3:
				cout<<"\nG. Ruger (Reduces police presence to 15%, Current Rating="<<20-profile.GunRate<<"%) - $2900."<<endl;
				cout<<"\t$"<<2900-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=2900-TradeIn;
				buyGun="Ruger";
				break;
			case 4:
				cout<<"\nG. Saturday night Special (Reduces police presence to 10%, Current Rating="<<20-profile.GunRate<<"%) - $3100."<<endl;
				cout<<"\t$"<<3100-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=3100-TradeIn;
				buyGun="Saturday night Special";
				break;
		}
	}
	cout<<"\nSelection (0 to cancel): ";
	cin>>chrChoice;

	//check for duplicate letters and proceed with purchase
	if ((chrChoice=='A' || chrChoice=='a') && boolDrugPresent[0]==true)
	{
		BuyingDrugs("ACID", intTemp[1]);
	}
	else if (chrChoice=='0')
	{
		CityOperations(false);
	}
	else if ((chrChoice=='C' || chrChoice=='c') && boolDrugPresent[1]==true)
	{
		BuyingDrugs("COCAINE", intTemp[13]);
	}
	else if ((chrChoice=='G' || chrChoice=='g') && boolDrugPresent[6]==true)
	{
		BuyingGun(buyGun, intTemp[13]);
	}
	else if ((chrChoice=='M' || chrChoice=='m') && boolDrugPresent[3]==true)
	{
		BuyingDrugs("MDA (Ecstasy)", intTemp[6]);
	}
	else if ((chrChoice=='L' || chrChoice=='l') && boolDrugPresent[2]==true)
	{
		BuyingDrugs("LUDES", intTemp[5]);
	}
	else if ((chrChoice=='O' || chrChoice=='o') && boolDrugPresent[4]==true)
	{
		BuyingDrugs("OPIUM", intTemp[7]);
	}
	else if ((chrChoice=='W' || chrChoice=='w') && boolDrugPresent[5]==true)
	{
		BuyingDrugs("WEED", intTemp[12]);
	}
	//for duplicate H's
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==true && twoH==true))
	{
		CheckWhichDrug('h', intTemp);
	}
	//for none duplicate
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==false || twoH==false))
	{
		for (i=0; i<=11; i++)
		{
			if (strDrugArray=="HASHISH")
			{
				BuyingDrugs("HASHISH", intTemp[3]);
				i=12;
			}
			if (strDrugArray=="HERION")
			{
				BuyingDrugs("HERION", intTemp[4]);
				i=12;
			}
		}
	}
	//for duplicate P's
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==true && twoP==true))
	{
		CheckWhichDrug('p', intTemp);
	}
	//for none duplicate
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==false || twoP==false))
	{
		for (i=0; i<=11; i++)
		{
			if (strDrugArray=="PCP")
			{
				BuyingDrugs("PCP", intTemp[8]);
				i=12;
			}
			if (strDrugArray=="PEYOTE")
			{
				BuyingDrugs("PEYOTE", intTemp[9]);
				i=12;
			}
		}
	}
	//for duplicate S's
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==true && twoS==true))
	{
		CheckWhichDrug('s', intTemp);
	}
	//for none duplicate
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==false || twoS==false))
	{
		for (i=0; i<=11; i++)
		{
			if (strDrugArray=="SHROOMS")
			{
				BuyingDrugs("SHROOMS", intTemp[10]);
				i=12;
			}
			if (strDrugArray=="SPEED")
			{
				BuyingDrugs("SPEED", intTemp[11]);
				i=12;
			}
		}
	}
	else
	{
		system("cls");
		PrintStats();
		SetConsoleColors(hConsole, 10, 0);
		cout<<"Invalid selection please pick again...\n\n";
		goto InvalidChoice;
	}

ABOUT THE CODE: intTemp and intDrugArray both hold the price of the drug (intTemp is used so that the ifs lower in the code will know exactly which index to find it in). strDrugArray holds the name of the drugs boolDrugPresent, oneS, twoS, oneP, twoP, oneH, twoH are all bools used to make sure the drug exists so that when you select like cocaine it won't let you buy it if cocaine wasn't available. the entire gun selection appears to work, never had a problem buying a gun WHAT BOGGLES MY MIND: As you can see when the menu is printed with each drug printed a bool is set to true so that we know it exists and in the else if string at the bottom only checks that bool and whether the selection is caps or lowercase. Because of this i see no reason for it to consider some of the drugs invalid. NOTE: this is also only sometimes but appears to be only with ACID, COCAINE, and LUDES and again appears to be that once it starts the error until the game is restarted you won't be able to select those drugs ever again. Below is my full code so you may play with it if you'd like but this issue should have no reason to be anywhere else in the code since the onyl variables used from other parts of the code prove to be correct when the menu is printed. (the code above starts on line 1416 in the full code) FULL CODE: requries using MFC in shared DLL was written with MSVC++ 6.0
[source code=cpp]
//for VC++
#include "stdafx.h"

//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> //also for string to int convertions and visa versa
#include <time.h>

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

//for ease of use
using namespace std;

//Global Variable Declaration
struct USERDATA
{
	string Name, Gun, Location;
	int Cash, Debt, Bank, Hentchmen, Space, Day;
	double GunRate;
};
struct LOCDATA
{
	string 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};
int intDrugArray[12];
string strDrugArray[12];
int intInvArray[12];
string strInvArray[12];
int intQuantArray[12];
string strPath;
bool boolGun;
int intGun;

//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();
int MenuHandler();
string ProfileMenu();
inline std::string stringify(int 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 BuyingGun(string Gun, int Price);
void ChangeLocMenu();
void LoanSharkMenu();
void SaveGame();
bool CheckSaved();
void HentchmenMenu();
int CheckHentchmen();
void ShowInfo();
void DeleteProfile();
void CheckInv();

//Start off function
int main(int argc, char* argv[])
{
	//Initialize random generator 
	srand ( time(NULL) );

	//Initialize global variables
	strPath=wsts(get_module_path_wide());
	for (i=0;i<=11;i++)
	{
		strInvArray=" ";
		strDrugArray=" ";
	}

	//Runs the menus and terminates the program if needed
	return MenuHandler();
}

int MenuHandler()
{
	//Function level Delcarations
	string strProfile, SavedFile=strPath + "\\profiles.dat", strTemp;
	char chrLine[2000];
	int intMnuOpt, cnt=0;

	//Displays Main Menu
	intMnuOpt=MainMenu();

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

	//Application Info
	if (intMnuOpt==1)
	{
		system("cls");
		ShowInfo();
	}

	//New Game code
	if (intMnuOpt==2)
	{
		//Variable initalization. 
		profile.Bank=0;
		profile.Day=0;
		profile.Cash=rand()%3000 + 2000;
		profile.Debt=rand()%9000 + 1000;
		profile.Gun="NONE";
		profile.GunRate=0;
		profile.Location="BRONX";
		profile.Hentchmen=rand()%4 + 7;
		profile.Space=(profile.Hentchmen * 10) + 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(true);
	}

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

		//ERROR checking
		if (strProfile=="NULL")
		{
			system("cls");
			cout<<"string ProfileMenu() returned ERROR code 'NULL' (Choice integer was left empty or invalid).\n\n";
			cout<<"Press any key to return to the Main Menu.";
			getch();
			MenuHandler();
		}

		//check for cancel msg
		if (strProfile=="MainMenu")
		{
			system("cls");
			MenuHandler();
		}

		//Load profile settings and start the game
		fstream inFile(SavedFile.c_str(), ios::in);

		inFile.getline(chrLine,2000);

		//convert to string array
		strTemp=chrLine[0];
		for (i=1; i<=1999; i++)
			strTemp=strTemp+chrLine;
		
		while (strTemp.find(strProfile)==std::string::npos)
		{
			inFile.getline(chrLine,2000);

			//convert to string array
			strTemp=chrLine[0];
			for (i=1; i<=1999; i++)
				strTemp=strTemp+chrLine;
		};

		//sets the profile.name
		strTemp=strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())-strTemp.find("=")-1);
		profile.Name=strTemp;

		//sets the rest of the variables
		while(strTemp.find("loc.maxdrugs")==std::string::npos)
		{
			inFile.getline(chrLine,2000);
			//convert to string array
			strTemp=chrLine[0];
			for (i=1; i<=1999; i++)
				strTemp=strTemp+chrLine;

			if ((strTemp.substr(0,strTemp.find("=")))=="profile.gun")
			{
				profile.Gun=strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())-strTemp.find("=")-1);
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.location")
			{
				profile.Location=strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())-strTemp.find("=")-1);
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.cash")
			{
				profile.Cash=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.debt")
			{
				profile.Debt=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.bank")
			{
				profile.Bank=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.hentchmen")
			{
				profile.Hentchmen=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.space")
			{
				profile.Space=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.day")
			{
				profile.Day=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="profile.gunrate")
			{
				profile.GunRate=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="loc.name")
			{
				loc.Name=strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())-strTemp.find("=")-1);
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="loc.police")
			{
				loc.Police=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="loc.mindrugs")
			{
				loc.minDrugs=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else if ((strTemp.substr(0,strTemp.find("=")))=="loc.maxdrugs")
			{
				loc.maxDrugs=atoi(strTemp.substr(strTemp.find("=")+1,strlen(strTemp.c_str())).c_str());
			}
			else
			{
				if (strTemp.find("=") !=std::string::npos)
				{
					strInvArray[cnt]=strTemp.substr(0,strTemp.find("="));
					intQuantArray[cnt]=atoi(strTemp.substr(strTemp.find("=")+1,strTemp.find(",")-strTemp.find("=")).c_str());
					intInvArray[cnt]=atoi(strTemp.substr(strTemp.find(",")+1,strlen(strTemp.c_str())).c_str());
					cnt++;
				}
			}
		}

		//start game
		CityOperations(true);
	}

	//Delete a profile
	if (intMnuOpt==4)
	{
		system("cls");
		DeleteProfile();
	}

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

	//Application terminator
	return 0;
}

//Operates the features of this location
void CityOperations(bool NewDay)
{
	int intTemp, cnt=0, DrugChecker;
	bool PickAgain;
	char chrChoice;
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);

	if (NewDay==true)
	{
		//increase the day
		profile.Day++;

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

		//set the randomized guns
		if(rand()%3+1==2)
		{
			boolGun=true;
			intGun=rand()%3+1;
		}
	
		system("cls");
		PrintStats();

		//sets up the drugs which are in this city (price, how many, what kind)	
		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:
					strDrugArray="ACID";
					intDrugArray=rand()%3400+1000;
					break;

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

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

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

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

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

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

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

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

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

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

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

				default:
					strDrugArray=" ";
					break;
			}	
		}

		//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
		SetConsoleColors(hConsole, 12, 0);

		//If it's a newday but not the first day run a random event to bust the user and make them bribe the cops
		if (NewDay==true && profile.Day !=1)
		{
			if((rand()%99+1)<=(loc.Police-profile.GunRate))
			{
				int money=profile.Cash*.2;
				string st;
				profile.Cash=profile.Cash-money;
				system("cls");
				PrintStats();
				//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
				SetConsoleColors(hConsole, 12, 0);
				cout<<"BUSTED !! -- Gotta bribe the cops, and it costs you 20% of your cash.\n\n";
				cout<<BufferStr("LOST: "+stringify(money),20)<<"REMAINING: "<<profile.Cash<<"\n\n";
			}
		}
	}
	else
	{
		system("cls");
		PrintStats();
	}

	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);
	//print city menu
	cout<<"Welcome to "<<loc.Name<<"!\n";
	
	//if its the home city [BRONX] then display spec menu
	if (loc.Name=="BRONX")
	{
specPickAgain:
		cout<<"1. Check out what's available.\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<<"7. Check Inventory.\n";
		cout<<"8. Quit.\n";
		cout<<"Selection: ";
		//await choice
		cin>>chrChoice;

		switch (chrChoice)
		{
			case '1':
				BuyDrugsMenu();
				break;

			case '2':
				SellDrugsMenu();
				break;

			case '3':
				ChangeLocMenu();
				break;

			case '4':
				BankMenu();
				break;

			case '5':
				LoanSharkMenu();
				break;

			case '6':
				SaveGame();
				break;

			case '7':
				CheckInv();
				break;

			case '8':
				system("cls");
				SetConsoleColors(hConsole, 15, 0);
				cout<<"Thank you for playing \"Drug Wars\" clone -- By: Derik Hammer.";
				getch();
				break;

			default:
				system("cls");
				PrintStats();
				//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
				SetConsoleColors(hConsole, 10, 0);
				cout<<"INVALID CHOICE PICK AGAIN!\n\n";
				goto specPickAgain;
				break;
		}
	}
	//if its the city [BROOKLYN] then display spec menu
	else if (loc.Name=="BROOKLYN")
	{
specPickAgain2:
		cout<<"1. Check out what's available.\n";
		cout<<"2. Sell Drugs.\n";
		cout<<"3. Change location.\n";
		cout<<"4. Exchange Hentchmen.\n";
		cout<<"5. Check Inventory.\n";
		cout<<"Selection: ";
		//await choice
		cin>>chrChoice;

		switch (chrChoice)
		{
			case '1':
				BuyDrugsMenu();
				break;
			case '2':
				SellDrugsMenu();
				break;
			case '3':
				ChangeLocMenu();
				break;
			case '4':
				HentchmenMenu();
				break;
			case '5':
				CheckInv();
				break;
			default:
				system("cls");
				PrintStats();
				//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
				SetConsoleColors(hConsole, 10, 0);
				cout<<"INVALID CHOICE PICK AGAIN!\n\n";
				goto specPickAgain2;
				break;
		}
	}
	//if its the city [MANHATTAN] then display spec menu
	else if (loc.Name=="MANHATTAN")
	{
specPickAgain3:
		cout<<"1. Check out what's available.\n";
		cout<<"2. Sell Drugs.\n";
		cout<<"3. Change location.\n";
		cout<<"4. Exchange Hentchmen.\n";
		cout<<"5. Check Inventory.\n";
		cout<<"Selection: ";
		//await choice
		cin>>chrChoice;

		switch (chrChoice)
		{
			case '1':
				BuyDrugsMenu();
				break;
			case '2':
				SellDrugsMenu();
				break;
			case '3':
				ChangeLocMenu();
				break;
			case '4':
				HentchmenMenu();
				break;
			case '5':
				CheckInv();
				break;
			default:
				system("cls");
				PrintStats();
				//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
				SetConsoleColors(hConsole, 10, 0);
				cout<<"INVALID CHOICE PICK AGAIN!\n\n";
				goto specPickAgain3;
				break;
		}
	}
	else
	{
normPickAgain:
		cout<<"1. Check out available Drugs.\n";
		cout<<"2. Sell Drugs.\n";
		cout<<"3. Change location.\n";
		cout<<"4. Check Inventory.\n";
		cout<<"Selection: ";
		//await choice
		cin>>chrChoice;

		switch (chrChoice)
		{
			case '1':
				BuyDrugsMenu();
				break;

			case '2':
				SellDrugsMenu();
				break;

			case '3':
				ChangeLocMenu();
				break;

			case '4':
				CheckInv();
				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);
}

//checks your inventory
void CheckInv()
{
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	int cnt=1, a;

	//print inventory
	system("cls");
	PrintStats();
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);
	cout<<"This is what you got:"<<endl<<endl;
	for(a=0; a<=11; a++)
	{
		if(strInvArray[a] !=" ")
		{
			cout<<BufferStr(stringify(cnt)+": "+strInvArray[a],12); cout<<" - Quantity: "<<intQuantArray[a]<<", bought @ $";
			cout<<intInvArray[a]<<".\n";
			cnt++;
		}	
	}	
	cout<<"\nPress any key to return to your city...";
	getch();

	//return to city
	CityOperations(false);
}

//preforms bank operations
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;
	}
	//await choice
	cout<<"\nSelection (0 to cancel): ";
	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=='0')
	{
		//return to your city
		CityOperations(false);
	}
	else
		BankMenu();

	CityOperations(false);

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);
}
void SellDrugsMenu()
{
	//Function level Declarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	int cnt, cnt2, x, intSell[12], tmpQuant[12];
	string strQuant, strChoice;

	//print menu
	system("cls");
	PrintStats();
	//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
	SetConsoleColors(hConsole, 12, 0);
	cout<<"NOTE: You may only sell drugs which this city is buying.\n";
	cout<<"      See the Inventory option for an accurate list of your drugs.\n\n";
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);
	cout<<"What drugs do you want to sell?\n\n";

	cnt2=1;
	//prints the sell options (can only sell to citys who are buying)
	for (cnt=0;cnt<12;cnt++)
	{
		for (x=0;x<=11;x++)
		{
			if(strDrugArray[cnt]==strInvArray[x] && strDrugArray[cnt] !=" ")
			{
				cout<<BufferStr(stringify(cnt2)+": "+strInvArray[x],12); cout<<" - Quantity: "<<intQuantArray[x]<<", bought @ $";
				cout<<intInvArray[x]<<", selling @ $"<<intDrugArray[cnt]<<"\n";
				intSell[cnt2]=cnt;
				tmpQuant[cnt2]=intQuantArray[x];
				cnt2++;
			}
		}
	}

	//give option to sell gun (3/4 value)
	int intGunPrice;
	if(profile.Gun !="NONE")
	{
		if(profile.Gun=="BARETTA")
		{
			intGunPrice=3000*.75;
			cout<<"G. Baretta - bought @ $3000, selling @ $"<<intGunPrice<<endl;
		}
		else if(profile.Gun==".38SPEC")
		{
			intGunPrice=3500*.75;
			cout<<"G. .38 Special - bought @ $3500, selling @ $"<<intGunPrice<<endl;
		}
		else if(profile.Gun=="SATNIGHTSPEC")
		{
			intGunPrice=3100*.75;
			cout<<"G. Saturday Night Special - bought @ $3100, selling @ $"<<intGunPrice<<endl;
		}
		else if(profile.Gun=="RUGER")
		{
			intGunPrice=2900*.75;
			cout<<"G. Ruger - bought @ $2900, selling @ $"<<intGunPrice<<endl;
		}
	}

	cout<<"\nSelect Drug to Sell (0 to cancel): ";
	cin>>strChoice;

	//check for gun selection
	if(strChoice=="G" || strChoice=="g")
		goto Sell_Gun;

	//if the cancel value is entered return to the city
	if (atoi(strChoice.c_str())==0 && strChoice=="0")
		goto City;

	//if it's a letter send it to the invalid choice menu
	if (atoi(strChoice.c_str())==0 && strChoice !="0")
		strChoice="9999";
	
	//reprint menu if invalid drug is choosen
	while (atoi(strChoice.c_str())>cnt2-1 || atoi(strChoice.c_str())<0)
	{
		system("cls");
		PrintStats();
		//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
		SetConsoleColors(hConsole, 12, 0);
		cout<<"NOTE: You may only sell drugs which this city is buying.\n";
		cout<<"      See the Inventory option for an accurate list of your drugs.\n\n";
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"INVALID DRUG CHOICE PLEASE CHOOSE AGAIN!\n\n";
		cout<<"What drugs do you want to sell?\n\n";
		cnt2=1;
		//prints the sell options (can only sell to citys who are buying)
		for (cnt=0;cnt<12;cnt++)
		{
			for (x=0;x<=11;x++)
			{
				if(strDrugArray[cnt]==strInvArray[x] && strDrugArray[cnt] !=" ")
				{
					cout<<BufferStr(stringify(cnt2)+": "+strInvArray[x],12); cout<<" - Quantity: "<<intQuantArray[x]<<", bought @ $";
					cout<<intInvArray[x]<<", selling @ $"<<intDrugArray[cnt]<<"\n";
					intSell[cnt2]=cnt;
					cnt2++;
				}
			}
		}
		
		cout<<"\nSelect Drug to Sell (0 to cancel): ";
		cin>>strChoice;

		//check for gun selection
		if(strChoice=="G" || strChoice=="g")
			goto Sell_Gun;

		//if it's a letter send it to the invalid choice menu
		if (atoi(strChoice.c_str())==0 && strChoice !="0")
			strChoice="9999";
	}

	//if the cancel value is entered return to the city
	if (atoi(strChoice.c_str())==0 && strChoice=="0")
		goto City;

	cout<<"\nQuantity (0 to cancel): ";
	cin>>strQuant;

	//if the cancel value is entered return to the city
	if (atoi(strQuant.c_str())==0 && strQuant=="0")
		goto City;

	//if it's a letter send it to the invalid choice menu
	if (atoi(strQuant.c_str())==0 && strQuant !="0")
		strQuant="9999";

	//reprint menu if invalid quantity is choosen
	while ((atoi(strQuant.c_str())>tmpQuant[atoi(strChoice.c_str())]) || (atoi(strQuant.c_str())<0))
	{
		system("cls");
		PrintStats();
		//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
		SetConsoleColors(hConsole, 12, 0);
		cout<<"NOTE: You may only sell the drug which this city is buying.\n";
		cout<<"      See the Inventory option for an accurate list of your drugs.\n\n";
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"INVALID DRUG CHOICE PLEASE CHOOSE AGAIN!\n\n";
		cout<<"What drugs do you want to sell?\n\n";
		cout<<"NOTE: You may only sell drugs which this city is buying, See the Inventory option for an accurate list of your drugs.\n\n";
		cnt=0;
		cnt2=1;
		//prints the sell options (can only sell to citys who are buying)
		while (cnt<12 && strDrugArray[cnt] !=" ")
		{
			for (x=0;x<=11;x++)
			{
				if(strDrugArray[cnt]==strInvArray[x])
				{
					cout<<BufferStr(stringify(cnt2)+": "+strInvArray[x],12); cout<<" - Quantity: ";
					cout<<intQuantArray[x]<<", bought @ $";
					cout<<intInvArray[x]<<", selling @ $"<<intDrugArray[cnt]<<"\n";
					intSell[cnt2]=cnt;
					cnt2++;
				}
			}
			cnt++;
		}

		cout<<"\nSelect Drug to Sell (0 to cancel): "<<strChoice<<"\n";

		cout<<"\nQuantity (0 to cancel): ";
		cin>>strQuant;

		//if it's a letter send it to the invalid choice menu
		if (atoi(strQuant.c_str())==0 && strQuant !="0")
			strQuant="9999";
	}

	//if the cancel value is entered return to the city
	if (atoi(strQuant.c_str())==0 && strQuant=="0")
		goto City;

	//empty out inv of the drugs sold and update related variables
	for(i=0;i<=11;i++)
	{
		if(strInvArray==strDrugArray[intSell[atoi(strChoice.c_str())]])
		{
			profile.Space=profile.Space+atoi(strQuant.c_str());
			profile.Cash=profile.Cash+(atoi(strQuant.c_str())*intDrugArray[intSell[atoi(strChoice.c_str())]]);
			if(atoi(strQuant.c_str())<intQuantArray)
			{
				intQuantArray=intQuantArray-atoi(strQuant.c_str());
			}
			else
			{
				intQuantArray=0;
				intInvArray=0;
				strInvArray=" ";
			}
			i=12;
		}
	}

	//an impossible if so that this code can only be reached with the goto
	if(intGunPrice==9999)
	{
Sell_Gun:
		profile.Cash=profile.Cash+intGunPrice;
		profile.Gun="NONE";
		profile.GunRate=0;
	}

	//return to the city
City:
	CityOperations(false);

	//reverts back to old colors
	SetConsoleColors(hConsole, 15, 0);
}

//determines whether to buy or sell hentchmen
int CheckHentchmen()
{
	//Function level delcarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	string strChoice;

	//print menu
	system("cls");
	PrintStats();
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	SetConsoleColors(hConsole, 10, 0);
RePrint:
	cout<<"What type of business will we be doing today?\n\n";
	cout<<"1. Recruiting Hentchmen - $10,000 each\n";
	cout<<"2. Selling Hentchmen - $6,000 each\n\n";
	cout<<"Selection (0 to cancel): ";
	//await choice
	cin>>strChoice;
	
	//check choice's validity
	if(strChoice !="1" && strChoice !="2" && strChoice !="0")
	{
		system("cls");
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"INVALID SELECTION PLEASE PICK AGAIN!\n\n";
		goto RePrint;
	}
	else
		return (atoi(strChoice.c_str()));

}

//buys and sells hentchmen
void HentchmenMenu()
{
	//Function level declarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	int intCheck;
	string strChoice;

	//if you have 0 men you can't sell any
	if(profile.Hentchmen==0)
	{
		//print menu
		system("cls");
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"How many Hentchmen would you like to buy (MAX: 24)? - $10,000 each\n\n";
		cout<<"Selection (0 to cancel): ";
		//await choice
		cin>>strChoice;

		//if it's a letter send it to the invalid choice menu
		if (atoi(strChoice.c_str())==0 && strChoice !="0")
			strChoice="9999";
		
		//if it's an invalid choice
		while(atoi(strChoice.c_str())*10000>profile.Cash || atoi(strChoice.c_str())<0 || profile.Hentchmen+atoi(strChoice.c_str())>24)
		{
			//print menu
			system("cls");
			PrintStats();
			//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
			SetConsoleColors(hConsole, 10, 0);
			cout<<"INVALID SELECTION PLEASE CHOICE AGAIN!\n\n";
			cout<<"How many Hentchmen would you like to buy (MAX: 24)? - $10,000 each\n\n";
			cout<<"Selection (0 to cancel): ";
			//await choice
			cin>>strChoice;

			//if it's a letter send it to the invalid choice menu
			if (atoi(strChoice.c_str())==0 && strChoice !="0")
				strChoice="9999";
		}

		//rewrite variables to finish sale
		if(strChoice !="0")
		{
			profile.Cash=profile.Cash-(atoi(strChoice.c_str())*10000);
			profile.Hentchmen=profile.Hentchmen+atoi(strChoice.c_str());
			profile.Space=profile.Space+(atoi(strChoice.c_str())*10);
		}
	}
	//if you have 24 men you can't buy any
	else if(profile.Hentchmen==24)
	{
		//print menu
		system("cls");
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"How many Hentchmen would you like to sell (MAX: "<<profile.Hentchmen<<")?"<<endl;
		cout<<"\t$6,000 each (costs 10 space per Hentchman)\n\n";
		cout<<"Selection (0 to cancel): ";
		//await choice
		cin>>strChoice;

		//if it's a letter send it to the invalid choice menu
		if (atoi(strChoice.c_str())==0 && strChoice !="0")
			strChoice="9999";
		
		//if it's an invalid choice
		while(atoi(strChoice.c_str())>profile.Hentchmen || atoi(strChoice.c_str())<0 || (profile.Space-(atoi(strChoice.c_str())*10))<0)
		{
			//print menu
			system("cls");
			PrintStats();
			//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
			SetConsoleColors(hConsole, 10, 0);
			cout<<"INVALID SELECTION PLEASE CHOICE AGAIN!\n\n";
			cout<<"How many Hentchmen would you like to sell (MAX: "<<profile.Hentchmen<<")?"<<endl;
			cout<<"\t$6,000 each (costs 10 space per Hentchman)\n\n";
			cout<<"Selection (0 to cancel): ";
			//await choice
			cin>>strChoice;

			//if it's a letter send it to the invalid choice menu
			if (atoi(strChoice.c_str())==0 && strChoice !="0")
				strChoice="9999";
		}

		//rewrite variables to finish sale
		if(strChoice !="0")
		{
			profile.Cash=profile.Cash+(atoi(strChoice.c_str())*6000);
			profile.Hentchmen=profile.Hentchmen-atoi(strChoice.c_str());
			profile.Space=profile.Space-(atoi(strChoice.c_str())*10);
		}
	}
	//check to see what you want to do (buy/sell)
	else
	{
		intCheck=CheckHentchmen();
		//check for cancel signal
		if(intCheck==0)
		{
			goto End_Func;
		}
		//if they choose buy then do that menu
		else if(intCheck==1)
		{
			//print menu
			system("cls");
			PrintStats();
			//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
			SetConsoleColors(hConsole, 10, 0);
			cout<<"How many Hentchmen would you like to buy (MAX: 24)? - $10,000 each\n\n";
			cout<<"Selection (0 to cancel): ";
			//await choice
			cin>>strChoice;

			//if it's a letter send it to the invalid choice menu
			if (atoi(strChoice.c_str())==0 && strChoice !="0")
				strChoice="9999";
			
			//if it's an invalid choice
			while(atoi(strChoice.c_str())*10000>profile.Cash || atoi(strChoice.c_str())<0 || profile.Hentchmen+atoi(strChoice.c_str())>24)
			{
				//print menu
				system("cls");
				PrintStats();
				//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
				SetConsoleColors(hConsole, 10, 0);
				cout<<"INVALID SELECTION PLEASE CHOICE AGAIN!\n\n";
				cout<<"How many Hentchmen would you like to buy (MAX: 24)? - $10,000 each\n\n";
				cout<<"Selection (0 to cancel): ";
				//await choice
				cin>>strChoice;

				//if it's a letter send it to the invalid choice menu
				if (atoi(strChoice.c_str())==0 && strChoice !="0")
					strChoice="9999";
			}

			//rewrite variables to finish sale
			if(strChoice !="0")
			{
				profile.Cash=profile.Cash-(atoi(strChoice.c_str())*10000);
				profile.Hentchmen=profile.Hentchmen+atoi(strChoice.c_str());
				profile.Space=profile.Space+(atoi(strChoice.c_str())*10);
			}
		}
		//if they choose sell then do that menu
		else if(intCheck==2)
		{
			//print menu
			system("cls");
			PrintStats();
			//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
			SetConsoleColors(hConsole, 10, 0);
			cout<<"How many Hentchmen would you like to sell (MAX: "<<profile.Hentchmen<<")?"<<endl;
			cout<<"\t$6,000 each (costs 10 space per Hentchman)\n\n";
			cout<<"Selection (0 to cancel): ";
			//await choice
			cin>>strChoice;

			//if it's a letter send it to the invalid choice menu
			if (atoi(strChoice.c_str())==0 && strChoice !="0")
				strChoice="9999";
			
			//if it's an invalid choice
			while(atoi(strChoice.c_str())>profile.Hentchmen || atoi(strChoice.c_str())<0 || (profile.Space-(atoi(strChoice.c_str())*10))<0)
			{
				//print menu
				system("cls");
				PrintStats();
				//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
				SetConsoleColors(hConsole, 10, 0);
				cout<<"INVALID SELECTION PLEASE CHOICE AGAIN!\n\n";
				cout<<"How many Hentchmen would you like to sell (MAX: "<<profile.Hentchmen<<")?"<<endl;
				cout<<"\t$6,000 each (costs 10 space per Hentchman)\n\n";
				cout<<"Selection (0 to cancel): ";
				//await choice
				cin>>strChoice;

				//if it's a letter send it to the invalid choice menu
				if (atoi(strChoice.c_str())==0 && strChoice !="0")
					strChoice="9999";
			}

			//rewrite variables to finish sale
			if(strChoice !="0")
			{
				profile.Cash=profile.Cash+(atoi(strChoice.c_str())*6000);
				profile.Hentchmen=profile.Hentchmen-atoi(strChoice.c_str());
				profile.Space=profile.Space-(atoi(strChoice.c_str())*10);
			}
		}
	}

End_Func:
	//return to old colors
	SetConsoleColors(hConsole, 15, 0);

	//go back to city
	CityOperations(false);
}

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);
	string strAmt;

	//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 (0 to cancel): ";
	cin>>strAmt;
	
	while (((atoi(strAmt.c_str())*Price)>profile.Cash) || (atoi(strAmt.c_str())>profile.Space))
	{
		//print menu
		system("cls");
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"You don't have enough money or enough space for that much "<<Drug<<"!\n\n";
		cout<<"How much "<<Drug<<" you want? ($"<<Price<<" each)"<<endl;
		cout<<"Quantity (0 to cancel): ";
		cin>>strAmt;
	}

	//updates the space in your inv
	profile.Space=profile.Space-atoi(strAmt.c_str());
	profile.Cash=profile.Cash-(atoi(strAmt.c_str())*Price);

	//fills the drug into the available array slot
	if (atoi(strAmt.c_str()) !=0)
	{
		//add it to drugs that are alrdy there
		for (i=0; i<=11; i++)
		{
			if (strInvArray==Drug)
			{
				//divides the two costs out so that it accurately represents how much you paid for everything
				intInvArray=((intQuantArray*intInvArray)+(Price*atoi(strAmt.c_str())))/(intQuantArray+atoi(strAmt.c_str()));
				intQuantArray=intQuantArray+atoi(strAmt.c_str());
				goto End_If;
			}
		}
		//add it to empty spot if drug wasn't found in inv
		for (i=0; i<=11; i++)
		{
			if (intInvArray==0)
			{
				strInvArray=Drug;
				intInvArray=Price;
				intQuantArray=atoi(strAmt.c_str());
				i=12;
			}
		}
	}
End_If:

	//reverts back to old colors
	SetConsoleColors(hConsole, 10, 0);

	BuyDrugsMenu();
}

void CheckWhichDrug(char chrDrug, int intTemp[12])
{
	//Function level Declarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);
	char chrChoice;

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

	switch (chrDrug)
	{
		case 'h':
			cout<<"Did you want HASHISH or HERION?\n\n";
			cout<<"1. HASHISH.\n";
			cout<<"2. HERION.\n";
			cout<<"Selection (0 to cancel): ";
			//await choice
			cin>>chrChoice;

			switch (chrChoice)
			{
				case '0':
					BuyDrugsMenu();
				case '1':
					BuyingDrugs("HASHISH", intTemp[3]);
					break;
				case '2':
					BuyingDrugs("HERION", intTemp[4]);
					break;
				default:
					goto RePick;
					break;
			}
			break;

		case 'p':
			cout<<"Did you want PCP or PEYOTE?\n\n";
			cout<<"1. PCP.\n";
			cout<<"2. PEYOTE.\n";
			cout<<"Selection (0 to cancel): ";
			//await choice
			cin>>chrChoice;

			switch (chrChoice)
			{
				case '0':
					BuyDrugsMenu();
				case '1':
					BuyingDrugs("PCP", intTemp[8]);
					break;
				case '2':
					BuyingDrugs("PEYOTE", intTemp[9]);
					break;
				default:
					goto RePick;
					break;
			}
			break;

		case 's':
			cout<<"Did you want SHROOMS or SPEED?\n\n";
			cout<<"1. SHROOMS.\n";
			cout<<"2. SPEED.\n";
			cout<<"Selection (0 to cancel): ";
			//await choice
			cin>>chrChoice;

			switch (chrChoice)
			{
				case '0':
					BuyDrugsMenu();
				case '1':
					BuyingDrugs("SHROOMS", intTemp[10]);
					break;
				case '2':
					BuyingDrugs("SPEED", intTemp[11]);
					break;
				default:
					goto RePick;
					break;
			}
			break;
	}
}

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

	//initialize function level declarations
	for (i=0;i<=6;i++)
		boolDrugPresent=false;

	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 ((strDrugArray !=" ") && (intDrugArray<=profile.Cash))
			goto SkipFor;
	}
	cout<<"Your broke! Go somewhere else or sell some of your product to make up the $$$.\n\n";
	cout<<"Press any key to return to \""<<loc.Name<<"\"";
	getch();
	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 (strDrugArray=="ACID")
		{
			cout<<"A. ACID - $"<<intDrugArray<<endl;
			intTemp[1]=intDrugArray;
			boolDrugPresent[0]=true;
		}
		else if (strDrugArray=="COCAINE")
		{
			cout<<"C. COCAINE - $"<<intDrugArray<<endl;
			intTemp[2]=intDrugArray;
			boolDrugPresent[1]=true;
		}
		else if (strDrugArray=="HASHISH")
		{
			cout<<"H. HASHISH - $"<<intDrugArray<<endl;
			intTemp[3]=intDrugArray;
			oneH=true;
		}
		else if (strDrugArray=="HERION")
		{
			cout<<"H. HERION - $"<<intDrugArray<<endl;
			intTemp[4]=intDrugArray;
			twoH=true;
		}
		else if (strDrugArray=="LUDES")
		{
			cout<<"L. LUDES - $"<<intDrugArray<<endl;
			intTemp[5]=intDrugArray;
			boolDrugPresent[2]=true;
		}
		else if (strDrugArray=="MDA (Ecstasy)")
		{
			cout<<"M. MDA (Ecstasy) - $"<<intDrugArray<<endl;
			intTemp[6]=intDrugArray;
			boolDrugPresent[3]=true;
		}
		else if (strDrugArray=="OPIUM")
		{
			cout<<"O. OPIUM - $"<<intDrugArray<<endl;
			intTemp[7]=intDrugArray;
			boolDrugPresent[4]=true;
		}
		else if (strDrugArray=="PCP")
		{
			cout<<"P. PCP - $"<<intDrugArray<<endl;
			intTemp[8]=intDrugArray;
			oneP=true;
		}
		else if (strDrugArray=="PEYOTE")
		{
			cout<<"P. PEYOTE - $"<<intDrugArray<<endl;
			intTemp[9]=intDrugArray;
			twoP=true;
		}
		else if (strDrugArray=="SHROOMS")
		{
			cout<<"S. SHROOMS - $"<<intDrugArray<<endl;
			intTemp[10]=intDrugArray;
			oneS=true;
		}
		else if (strDrugArray=="SPEED")
		{
			cout<<"S. SPEED - $"<<intDrugArray<<endl;
			intTemp[11]=intDrugArray;
			twoS=true;
		}
		else if (strDrugArray=="WEED")
		{
			cout<<"W. WEED - $"<<intDrugArray<<endl;
			intTemp[12]=intDrugArray;
			boolDrugPresent[5]=true;
		}
	}

	//print gun options and determine price with trade-in value of old gun
	if (boolGun==true)
	{
		boolDrugPresent[6]=true;

		if (profile.Gun=="BARETTA")
			TradeIn=1500;
		if (profile.Gun==".38SPEC")
			TradeIn=1725;
		if (profile.Gun=="RUGER")
			TradeIn=1450;
		if (profile.Gun=="SATNIGHTSPEC")
			TradeIn=1600;
		if (profile.Gun=="NONE")
			TradeIn=0;

		switch (intGun)
		{
			case 1:
				cout<<"\nG. Baretta (Reduces police presence to 13%, Current Rating="<<20-profile.GunRate<<"%) - $3000."<<endl;
				cout<<"\t$"<<3000-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=3000-TradeIn;
				buyGun="Baretta";
				break;
			case 2:
				cout<<"\nG. .38 Special (Reduces police presence to 7%, Current Rating="<<20-profile.GunRate<<"%) - $3500."<<endl;
				cout<<"\t$"<<3500-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=3500-TradeIn;
				buyGun=".38 Special";
				break;
			case 3:
				cout<<"\nG. Ruger (Reduces police presence to 15%, Current Rating="<<20-profile.GunRate<<"%) - $2900."<<endl;
				cout<<"\t$"<<2900-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=2900-TradeIn;
				buyGun="Ruger";
				break;
			case 4:
				cout<<"\nG. Saturday night Special (Reduces police presence to 10%, Current Rating="<<20-profile.GunRate<<"%) - $3100."<<endl;
				cout<<"\t$"<<3100-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
				intTemp[13]=3100-TradeIn;
				buyGun="Saturday night Special";
				break;
		}
	}
	cout<<"\nSelection (0 to cancel): ";
	cin>>chrChoice;

	//check for duplicate letters and proceed with purchase
	if ((chrChoice=='A' || chrChoice=='a') && boolDrugPresent[0]==true)
	{
		BuyingDrugs("ACID", intTemp[1]);
	}
	else if (chrChoice=='0')
	{
		CityOperations(false);
	}
	else if ((chrChoice=='C' || chrChoice=='c') && boolDrugPresent[1]==true)
	{
		BuyingDrugs("COCAINE", intTemp[13]);
	}
	else if ((chrChoice=='G' || chrChoice=='g') && boolDrugPresent[6]==true)
	{
		BuyingGun(buyGun, intTemp[13]);
	}
	else if ((chrChoice=='M' || chrChoice=='m') && boolDrugPresent[3]==true)
	{
		BuyingDrugs("MDA (Ecstasy)", intTemp[6]);
	}
	else if ((chrChoice=='L' || chrChoice=='l') && boolDrugPresent[2]==true)
	{
		BuyingDrugs("LUDES", intTemp[5]);
	}
	else if ((chrChoice=='O' || chrChoice=='o') && boolDrugPresent[4]==true)
	{
		BuyingDrugs("OPIUM", intTemp[7]);
	}
	else if ((chrChoice=='W' || chrChoice=='w') && boolDrugPresent[5]==true)
	{
		BuyingDrugs("WEED", intTemp[12]);
	}
	//for duplicate H's
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==true && twoH==true))
	{
		CheckWhichDrug('h', intTemp);
	}
	//for none duplicate
	else if ((chrChoice=='H' || chrChoice=='h') && (oneH==false || twoH==false))
	{
		for (i=0; i<=11; i++)
		{
			if (strDrugArray=="HASHISH")
			{
				BuyingDrugs("HASHISH", intTemp[3]);
				i=12;
			}
			if (strDrugArray=="HERION")
			{
				BuyingDrugs("HERION", intTemp[4]);
				i=12;
			}
		}
	}
	//for duplicate P's
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==true && twoP==true))
	{
		CheckWhichDrug('p', intTemp);
	}
	//for none duplicate
	else if ((chrChoice=='P' || chrChoice=='p') && (oneP==false || twoP==false))
	{
		for (i=0; i<=11; i++)
		{
			if (strDrugArray=="PCP")
			{
				BuyingDrugs("PCP", intTemp[8]);
				i=12;
			}
			if (strDrugArray=="PEYOTE")
			{
				BuyingDrugs("PEYOTE", intTemp[9]);
				i=12;
			}
		}
	}
	//for duplicate S's
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==true && twoS==true))
	{
		CheckWhichDrug('s', intTemp);
	}
	//for none duplicate
	else if ((chrChoice=='S' || chrChoice=='s') && (oneS==false || twoS==false))
	{
		for (i=0; i<=11; i++)
		{
			if (strDrugArray=="SHROOMS")
			{
				BuyingDrugs("SHROOMS", intTemp[10]);
				i=12;
			}
			if (strDrugArray=="SPEED")
			{
				BuyingDrugs("SPEED", intTemp[11]);
				i=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);

	//go back to city
	CityOperations(false);
}

void BuyingGun(string Gun, int Price)
{
	//Function level Declarations
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);

	//print menu
	system("cls");
	PrintStats();
	//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
	
	if (Price>profile.Cash)
	{
		//print menu
		system("cls");
		PrintStats();
		//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
		SetConsoleColors(hConsole, 10, 0);
		cout<<"You don't have enough money for the "<<Gun<<"!\n\n";
		cout<<"Press any key to return to the Buy Drugs menu."<<endl;
		getch();
		goto Back;
	}

	//updates info
	profile.Cash=profile.Cash-Price;
	if (Gun=="Saturday night Special")
	{
		profile.Gun="SATNIGHTSPEC";
		profile.GunRate=10;
	}
	if (Gun=="Baretta")
	{
		profile.Gun="BARETTA";
		profile.GunRate=13;
	}
	if (Gun==".38 Special")
	{
		profile.Gun=".38SPEC";
		profile.GunRate=7;
	}
	if (Gun=="Ruger")
	{
		profile.Gun="RUGER";
		profile.GunRate=5;
	}

	//reverts back to old colors
	SetConsoleColors(hConsole, 10, 0);

Back:
	BuyDrugsMenu();
}

void ChangeLocMenu()
{
	//Function level Declarations
	string strChoice;	
	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<<"0. Back to "<<loc.Name<<"\n";
	cout<<"Selection: ";
	//await selection
	cin>>strChoice;

	switch (atoi(strChoice.c_str()))
	{
		case BRONX:
			if (profile.Location=="BRONX")
				strChoice="9";
			profile.Location="BRONX";
			loc.Name="BRONX";
			loc.minDrugs=7;
			loc.maxDrugs=12;
			loc.Police=10;
			break;

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

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

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

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

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

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

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

		case 0:
			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 (strChoice=="0")
	{
		CityOperations(false);
	}
	else
	{
		CityOperations(true);
	}
}
void LoanSharkMenu()
{
	//Function level Declarations
	string strChoice, strAmt;
	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\n";
		cout<<"Selection (0 to cancel): ";
		//await choice
		cin>>strChoice;

		switch (atoi(strChoice.c_str()))
		{
			//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>>strAmt;
				if (atoi(strAmt.c_str())>profile.Cash || atoi(strAmt.c_str())<0 || atoi(strAmt.c_str())>profile.Debt)
				{
					system("cls");
					PrintStats();
					SetConsoleColors(hConsole, 10, 0);
					cout<<"Invalid $ amount please pick again.\n\n";
					goto PLoanAgain;
				}

				//redefines variables appropriatly
				profile.Cash=profile.Cash-atoi(strAmt.c_str());
				profile.Debt=profile.Debt-atoi(strAmt.c_str());

				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\n";
		cout<<"Selection (0 to cancel): ";
		//await choice
		cin>>strChoice;

		switch (atoi(strChoice.c_str()))
		{
			//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>>strAmt;

				//can't use negatives
				if (atoi(strAmt.c_str())<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 (atoi(strAmt.c_str())>=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+atoi(strAmt.c_str());
				profile.Debt=profile.Debt+atoi(strAmt.c_str());

				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);
}

//checks to see if the use already has a profile by that name saved
bool CheckSaved()
{
	string Data=strPath + "\\profiles.dat", strTemp;
	ifstream inFile(Data.c_str());

	//check for file existance
	if(!(inFile.good()))
	{
		inFile.close();
		//Create file
		ofstream outFile(Data.c_str());
		outFile.close();
	}

	while (inFile >> Data)
	{
		strTemp="profile.name=" + profile.Name;
		if (Data==strTemp)
		{
			inFile.close();
			return(true);
		}
	};
	
	inFile.close();
	return (false);
}

//rewrites the files needed for saving
void SaveGame()
{
	bool Saved;
	string Data=strPath + "\\profiles.dat", strOldData[100], strOldData2[100], strTemp;
	char chrLine[2000];
	int cnt=0;

	//empty strOldData incase this isn't the first save
	for (i=0; i<=99; i++)
		strOldData=" ";

	//empty strOldData2 incase this isn't the first save
	for (i=0; i<=99; i++)
		strOldData2=" ";

	//check to see if the game is overwritting or a new save
	Saved=CheckSaved();

	if (Saved==false)
	{
		fstream inFile(Data.c_str(), ios::in);

		//store information in file for reprint
		while (! inFile.eof())
		{
			inFile.getline(chrLine,2000);

			//convert to string array
			strOldData[cnt]=chrLine[0];
			for (i=1; i<=1999; i++)
				strOldData[cnt]=strOldData[cnt]+chrLine;

			cnt++;
		};
		inFile.close();
		
		//rewrite the old info
		cnt=1;
		fstream outFile(Data.c_str(), ios::out);
		
		if (!(strOldData[0]==" "))
			outFile<<strOldData[0];
		while (!(strOldData[cnt]==" "))
		{
			outFile<<endl<<strOldData[cnt];
			cnt++;
		};

		//write the new info
		outFile<<endl<<endl;
		outFile<<"profile.name="<<profile.Name<<endl;
		outFile<<"profile.gun="<<profile.Gun<<endl;
		outFile<<"profile.location="<<profile.Location<<endl;
		outFile<<"profile.cash="<<profile.Cash<<endl;
		outFile<<"profile.debt="<<profile.Debt<<endl;
		outFile<<"profile.bank="<<profile.Bank<<endl;
		outFile<<"profile.hentchmen="<<profile.Hentchmen<<endl;
		outFile<<"profile.space="<<profile.Space<<endl;
		outFile<<"profile.day="<<profile.Day<<endl;
		outFile<<"profile.gunrate="<<profile.GunRate<<endl;
		for (i=0;i<=11;i++)
		{
			if (strInvArray !=" ")
				outFile<<strInvArray<<"="<<intQuantArray<<","<<intInvArray<<endl;
		}
		outFile<<"loc.name="<<loc.Name<<endl;
		outFile<<"loc.police="<<loc.Police<<endl;
		outFile<<"loc.mindrugs="<<loc.minDrugs<<endl;
		outFile<<"loc.maxdrugs="<<loc.maxDrugs;	

		outFile.close();
		
	}
	else
	{
		//open file
		fstream inFile(Data.c_str(), ios::in);

		//store information in file before the saved game for reprint
		cnt=0;
		inFile.getline(chrLine,2000);

		//convert to string array
		strOldData[cnt]=chrLine[0];
		for (i=1; i<=1999; i++)
			strOldData[cnt]=strOldData[cnt]+chrLine;

		//load pre-saved game data
		while (strOldData[cnt].find(profile.Name)==std::string::npos)
		{
			cnt++;
			
			inFile.getline(chrLine,2000);

			//convert to string array
			strOldData[cnt]=chrLine[0];
			for (i=1; i<=1999; i++)
				strOldData[cnt]=strOldData[cnt]+chrLine;
		};

		//remove the profile from the pre-saved game data
		strOldData[cnt-1]=" ";
		strOldData[cnt]=" ";

		//if the profile was found on the first getline
		if (strOldData[1]==" ")
			strOldData[0]=" ";

		//store information in file after the saved game for reprint
		inFile.getline(chrLine,2000);

		//convert to string array
		strTemp=chrLine[0];
		for (i=1; i<=1999; i++)
			strTemp=strTemp+chrLine;

		//scan until it finds the line with the last stat in the saved game [loc.maxdrugs=12]
		while (strTemp.find("loc.maxdrugs=12")==std::string::npos)
		{
			inFile.getline(chrLine,2000);
			
			//convert to string array
			strTemp=chrLine[0];
			for (i=1; i<=1999; i++)
				strTemp=strTemp+chrLine;
		};

		//store the rest of the file
		cnt=0;
		while (!(inFile.eof()))
		{
			inFile.getline(chrLine,2000);

			//convert to string array
			strOldData2[cnt]=chrLine[0];
			for (i=1; i<=1999; i++)
				strOldData2[cnt]=strOldData2[cnt]+chrLine;

			cnt++;
		};

		//if the profile was found on the first getline
		if (strOldData2[1]==" ")
			strOldData2[0]=" ";

		inFile.close();
		
		//rewrite the begining old info [1]
		cnt=1;
		fstream outFile(Data.c_str(), ios::out);

		if (!(strOldData[0]==" "))
			outFile<<strOldData[0];

		while (!(strOldData[cnt]==" "))
		{
			outFile<<endl<<strOldData[cnt];
			cnt++;
		};

		//write new saved data
		outFile<<endl<<endl;
		outFile<<"profile.name="<<profile.Name<<endl;
		outFile<<"profile.gun="<<profile.Gun<<endl;
		outFile<<"profile.location="<<profile.Location<<endl;
		outFile<<"profile.cash="<<profile.Cash<<endl;
		outFile<<"profile.debt="<<profile.Debt<<endl;
		outFile<<"profile.bank="<<profile.Bank<<endl;
		outFile<<"profile.hentchmen="<<profile.Hentchmen<<endl;
		outFile<<"profile.space="<<profile.Space<<endl;
		outFile<<"profile.day="<<profile.Day<<endl;
		outFile<<"profile.gunrate="<<profile.GunRate<<endl;
		for (i=0;i<=11;i++)
		{
			if (strInvArray !=" ")
				outFile<<strInvArray<<"="<<intQuantArray<<","<<intInvArray<<endl;
		}
		outFile<<"loc.name="<<loc.Name<<endl;
		outFile<<"loc.police="<<loc.Police<<endl;
		outFile<<"loc.mindrugs="<<loc.minDrugs<<endl;
		outFile<<"loc.maxdrugs="<<loc.maxDrugs<<endl;	

		//rewrite the end old info [2]
		cnt=1;

		if (!(strOldData2[0]==" "))
			outFile<<strOldData2[0];

		while (!(strOldData2[cnt]==" "))
		{
			outFile<<endl<<strOldData2[cnt];
			cnt++;
		};

		outFile.close();
	}

	//resume game
	CityOperations(false);
}

 
 //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(int)");
   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";
	cout<<BufferStr("Gun: " + profile.Gun,20)<<"Day: "<<profile.Day<<"\n";
	cout<<"Free Space: "<<profile.Space<<"\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.
string ProfileMenu()
{
	//Function level Declarations
	string Profile[100], Data=strPath + "\\profiles.dat", strTemp;
	string strChoice="200";
	int cnt=0, intTemp;
	char chrLine[2000];
	HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
									FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 
									OPEN_EXISTING, 0, 0);

	//initialize the profile array
	for (i=0; i<=99; i++)
		Profile=" ";

	//storing the profiles into an array to be printed
	ifstream inFile(Data.c_str());

	//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
	SetConsoleColors(hConsole, 12, 0);
	system("cls");

	//check for file existence
	if(!(inFile.good()))
	{
		//Print menu
		cout<<"Drug Wars --- By: Derik Hammer\n\n";
		cout<<"File 'profiles.dat' was not found no saved games are available.\n\n";
		cout<<"Press any key to return to the Main Menu.";
		getch();
		inFile.close();
		//return to main menu
		system("cls");
		MenuHandler();
	}

	while (!(inFile.eof()))
	{
		inFile.getline(chrLine,2000);
		strTemp=chrLine;
		//look for the name locator
		if(!(strTemp.find("profile.name=")==std::string::npos))
		{
			intTemp=strTemp.find("name=")+5;
			//remake the string with chrLine
			strTemp=chrLine[intTemp];
			for(i=intTemp+1;i<=1999;i++)
				strTemp=strTemp+chrLine;
			Profile[cnt]=strTemp;
			cnt++;
		}
	};

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

	//check for which menu to use
	if (!(Profile[0]==" "))
	{
		//Print menu
		cnt=0;
		system("cls");
		cout<<"Drug Wars --- By: Derik Hammer\n\n";

		while (!(Profile[cnt]==" "))
		{
			cout<<cnt+1<<". "<<Profile[cnt]<<".\n";
			cnt++;
		};

		cout<<"\nSelection (0 to cancel): ";
		//Await choice
		cin>>strChoice;
		strTemp=Profile[atoi(strChoice.c_str())-1];

		//loops if invalid numbers are entered.
		while (strTemp==" ")
		{
			SetConsoleColors(hConsole, 10, 0);
			//Print menu
			cnt=0;
			system("cls");
			cout<<"Drug Wars --- By: Derik Hammer\n\n";

			while (!(Profile[cnt]==" "))
			{
				cout<<cnt+1<<". "<<Profile[cnt]<<".\n";
				cnt++;
			};

			cout<<"\nINVALID SELECTION PLEASE CHOOSE AGAIN!\n";
			cout<<"Selection (0 to cancel): ";
			//Await choice
			cin>>strChoice;
			strTemp=Profile[atoi(strChoice.c_str())];
		}
	}
	else
	{
		//if there's no saved games print this menu
		system("cls");
		cout<<"Drug Wars --- By: Derik Hammer\n\n";
		cout<<"Sorry no saved games were found.\n\n";
		cout<<"Press any key to go back to the Main Menu.";
		strChoice="0";
		getch();
	}

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

	//go back to main menu
	if (strChoice=="0")
		return "MainMenu";
	
	//Returns the name of the profile needed to be used
	if (!(strChoice=="200"))
		return(Profile[atoi(strChoice.c_str())-1]);

	//else return an error report
	return "NULL";
}

//gives some background about the game
void ShowInfo()
{
	//Function level Declarations
	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);

	cout<<"The idea for this game \"Drug Wars\" was thought up a long time ago by a person"<<endl;
	cout<<"unknown to me. Therefore I'm not taking credit for the consept nor for a lot of"<<endl;
	cout<<"the content. I made this program To learn C++ so now you will be playing my"<<endl;
	cout<<"version of \"Drug Wars\"."<<endl<<endl;
	cout<<"THE OBJECTIVE:"<<endl;
	cout<<"You are a drug dealer and you want to make as much money as possible and pay"<<endl;
	cout<<"off all your debt."<<endl<<endl;
	cout<<"HOW THINGS WORK:"<<endl;
	cout<<"In order to build up cash you need to buy and sell drugs. Different cities have"<<endl;
	cout<<"different amounts of drugs along with a better or worse chance of getting"<<endl;
	cout<<"caught by the cops. It's best to take note of which places you get caught at"<<endl;
	cout<<"the most. HINT: guns reduce the probability that you will get caught. Once you"<<endl;
	cout<<"get the hang of buying/selling you'll notice hentchmen and space. The space is"<<endl;
	cout<<"how many drugs you can carry at once and the more hentchmen the more space you"<<endl;
	cout<<"have. You can buy and sell hentchmen but they are expensive and when you find"<<endl;
	cout<<"some rediculously low drug prices you'll need to stock up so be careful with"<<endl;
	cout<<"both buying and selling."<<endl<<endl;

	//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
	SetConsoleColors(hConsole, 12, 0);

	cout<<"Press any key to scroll down..."<<endl<<endl;
	getch();

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

	cout<<"Police, in every game you need to have a bad guy, well here they are. As"<<endl;
	cout<<"printed above, cops appear at different times and more frequently in certain"<<endl;
	cout<<"cities. Guns help but will never make you immune. That's where the bank comes"<<endl;
	cout<<"in. The cops take 20% of your cash as a bride so you don't go to jail. If the"<<endl;
	cout<<"money's in the bank it's safe, however. Hope you enjoy!"<<endl<<endl;

	//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
	SetConsoleColors(hConsole, 12, 0);

	cout<<"Press any key to return to the main menu..."<<endl;
	getch();

	//revert to old colors
	SetConsoleColors(hConsole, 15, 0);
	
	system("cls");
	MenuHandler();
}

//Deletes already saved games
void DeleteProfile()
{
	//Function level Declarations
	string Data=strPath + "\\profiles.dat", strOldData[100], strOldData2[100], strTemp;
	char chrLine[2000];
	int cnt=0;

	//empty strOldData incase this isn't the first save
	for (i=0; i<=99; i++)
		strOldData=" ";

	//empty strOldData2 incase this isn't the first save
	for (i=0; i<=99; i++)
		strOldData2=" ";

	//find out which one to delete
	profile.Name=ProfileMenu();

	//Delete game
	//open file
	fstream inFile(Data.c_str(), ios::in);

	//store information in file before the saved game for reprint
	cnt=0;
	inFile.getline(chrLine,2000);

	//convert to string array
	strOldData[cnt]=chrLine[0];
	for (i=1; i<=1999; i++)
		strOldData[cnt]=strOldData[cnt]+chrLine;

	//load pre-saved game data
	while (strOldData[cnt].find(profile.Name)==std::string::npos)
	{
		cnt++;
			
		inFile.getline(chrLine,2000);

		//convert to string array
		strOldData[cnt]=chrLine[0];
		for (i=1; i<=1999; i++)
			strOldData[cnt]=strOldData[cnt]+chrLine;
	};

	//remove the profile from the pre-saved game data
	strOldData[cnt-1]=" ";
	strOldData[cnt]=" ";

	//if the profile was found on the first getline
	if (strOldData[1]==" ")
		strOldData[0]=" ";

	//store information in file after the saved game for reprint
	inFile.getline(chrLine,2000);

	//convert to string array
	strTemp=chrLine[0];
	for (i=1; i<=1999; i++)
		strTemp=strTemp+chrLine;

	//scan until it finds the line with the last stat in the saved game [loc.maxdrugs=12]
	while (strTemp.find("loc.maxdrugs=12")==std::string::npos)
	{
		inFile.getline(chrLine,2000);
			
		//convert to string array
		strTemp=chrLine[0];
		for (i=1; i<=1999; i++)
			strTemp=strTemp+chrLine;
	};

	//store the rest of the file
	cnt=0;
	while (!(inFile.eof()))
	{
		inFile.getline(chrLine,2000);

		//convert to string array
		strOldData2[cnt]=chrLine[0];
		for (i=1; i<=1999; i++)
			strOldData2[cnt]=strOldData2[cnt]+chrLine;

		cnt++;
	};

	//if the profile was found on the first getline
	if (strOldData2[1]==" ")
		strOldData2[0]=" ";

	inFile.close();
		
	//rewrite the begining old info [1]
	cnt=1;
	fstream outFile(Data.c_str(), ios::out);

	if (!(strOldData[0]==" "))
		outFile<<strOldData[0];

	while (!(strOldData[cnt]==" "))
	{
		outFile<<endl<<strOldData[cnt];
		cnt++;
	};

	//rewrite the end old info [2]
	cnt=1;

	if (!(strOldData2[0]==" "))
		outFile<<strOldData2[0];

	while (!(strOldData2[cnt]==" "))
	{
		outFile<<endl<<strOldData2[cnt];
		cnt++;
	};

	//close file
	outFile.close();

	//return to main menu
	system("cls");
	MenuHandler();
}

//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. Application Information.\n";
	cout<<"2. New Game.\n";
	cout<<"3. Load Profile.\n";
	cout<<"4. Delete Profiles.\n";
	cout<<"5. Quit.\n\n";
	cout<<"Selection: ";
	//Await choice
	cin>>chrChoice;
	
CheckAgain:
	switch (chrChoice)
	{
		//Proceed with App info
		case '1':
			//revert to old colors
			SetConsoleColors(hConsole, 15, 0);
			return (1);
			break;

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

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

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

		//Proceed with exiting the application
		case '5':
			//revert to old colors
			SetConsoleColors(hConsole, 15, 0);
			return (5);
			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. Application Information.\n";
			cout<<"2. New Game.\n";
			cout<<"3. Load Profile.\n";
			cout<<"4. Delete Profiles.\n";
			cout<<"5. Quit.\n\n";
			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
well it appears that no one can find my bug so here's my next problem:

in the function below you can sell your drugs to the people in the city which you are at. It's an uncommon bug but everyonce in a while it adds $10,000 to your cash after you complete a sale (that is $10,000 + the normal sell value).

[source code=cpp]
void SellDrugsMenu()
{
//Function level Declarations
HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0);
int cnt, cnt2, x, intSell[12], tmpQuant[12];
string strQuant, strChoice;

//print menu
system("cls");
PrintStats();
//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
SetConsoleColors(hConsole, 12, 0);
cout<<"NOTE: You may only sell drugs which this city is buying.\n";
cout<<" See the Inventory option for an accurate list of your drugs.\n\n";
//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
SetConsoleColors(hConsole, 10, 0);
cout<<"What drugs do you want to sell?\n\n";

cnt2=1;
//prints the sell options (can only sell to citys who are buying)
for (cnt=0;cnt<12;cnt++)
{
for (x=0;x<=11;x++)
{
if(strDrugArray[cnt]==strInvArray[x] && strDrugArray[cnt] !=" ")
{
cout<<BufferStr(stringify(cnt2)+": "+strInvArray[x],12); cout<<" - Quantity: "<<intQuantArray[x]<<", bought @ $";
cout<<intInvArray[x]<<", selling @ $"<<intDrugArray[cnt]<<"\n";
intSell[cnt2]=cnt;
tmpQuant[cnt2]=intQuantArray[x];
cnt2++;
}
}
}

//give option to sell gun (3/4 value)
int intGunPrice;
if(profile.Gun !="NONE")
{
if(profile.Gun=="BARETTA")
{
intGunPrice=3000*.75;
cout<<"G. Baretta - bought @ $3000, selling @ $"<<intGunPrice<<endl;
}
else if(profile.Gun==".38SPEC")
{
intGunPrice=3500*.75;
cout<<"G. .38 Special - bought @ $3500, selling @ $"<<intGunPrice<<endl;
}
else if(profile.Gun=="SATNIGHTSPEC")
{
intGunPrice=3100*.75;
cout<<"G. Saturday Night Special - bought @ $3100, selling @ $"<<intGunPrice<<endl;
}
else if(profile.Gun=="RUGER")
{
intGunPrice=2900*.75;
cout<<"G. Ruger - bought @ $2900, selling @ $"<<intGunPrice<<endl;
}
}

cout<<"\nSelect Drug to Sell (0 to cancel): ";
cin>>strChoice;

//check for gun selection
if(strChoice=="G" || strChoice=="g")
goto Sell_Gun;

//if the cancel value is entered return to the city
if (atoi(strChoice.c_str())==0 && strChoice=="0")
goto City;

//if it's a letter send it to the invalid choice menu
if (atoi(strChoice.c_str())==0 && strChoice !="0")
strChoice="9999";

//reprint menu if invalid drug is choosen
while (atoi(strChoice.c_str())>cnt2-1 || atoi(strChoice.c_str())<0)
{
system("cls");
PrintStats();
//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
SetConsoleColors(hConsole, 12, 0);
cout<<"NOTE: You may only sell drugs which this city is buying.\n";
cout<<" See the Inventory option for an accurate list of your drugs.\n\n";
//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
SetConsoleColors(hConsole, 10, 0);
cout<<"INVALID DRUG CHOICE PLEASE CHOOSE AGAIN!\n\n";
cout<<"What drugs do you want to sell?\n\n";
cnt2=1;
//prints the sell options (can only sell to citys who are buying)
for (cnt=0;cnt<12;cnt++)
{
for (x=0;x<=11;x++)
{
if(strDrugArray[cnt]==strInvArray[x] && strDrugArray[cnt] !=" ")
{
cout<<BufferStr(stringify(cnt2)+": "+strInvArray[x],12); cout<<" - Quantity: "<<intQuantArray[x]<<", bought @ $";
cout<<intInvArray[x]<<", selling @ $"<<intDrugArray[cnt]<<"\n";
intSell[cnt2]=cnt;
cnt2++;
}
}
}

cout<<"\nSelect Drug to Sell (0 to cancel): ";
cin>>strChoice;

//check for gun selection
if(strChoice=="G" || strChoice=="g")
goto Sell_Gun;

//if it's a letter send it to the invalid choice menu
if (atoi(strChoice.c_str())==0 && strChoice !="0")
strChoice="9999";
}

//if the cancel value is entered return to the city
if (atoi(strChoice.c_str())==0 && strChoice=="0")
goto City;

cout<<"\nQuantity (0 to cancel): ";
cin>>strQuant;

//if the cancel value is entered return to the city
if (atoi(strQuant.c_str())==0 && strQuant=="0")
goto City;

//if it's a letter send it to the invalid choice menu
if (atoi(strQuant.c_str())==0 && strQuant !="0")
strQuant="9999";

//reprint menu if invalid quantity is choosen
while ((atoi(strQuant.c_str())>tmpQuant[atoi(strChoice.c_str())]) || (atoi(strQuant.c_str())<0))
{
system("cls");
PrintStats();
//make stats 'RED' (12) with 'blk bg' (0) [warning std color]
SetConsoleColors(hConsole, 12, 0);
cout<<"NOTE: You may only sell the drug which this city is buying.\n";
cout<<" See the Inventory option for an accurate list of your drugs.\n\n";
//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
SetConsoleColors(hConsole, 10, 0);
cout<<"INVALID DRUG CHOICE PLEASE CHOOSE AGAIN!\n\n";
cout<<"What drugs do you want to sell?\n\n";
cout<<"NOTE: You may only sell drugs which this city is buying, See the Inventory option for an accurate list of your drugs.\n\n";
cnt=0;
cnt2=1;
//prints the sell options (can only sell to citys who are buying)
while (cnt<12 && strDrugArray[cnt] !=" ")
{
for (x=0;x<=11;x++)
{
if(strDrugArray[cnt]==strInvArray[x])
{
cout<<BufferStr(stringify(cnt2)+": "+strInvArray[x],12); cout<<" - Quantity: ";
cout<<intQuantArray[x]<<", bought @ $";
cout<<intInvArray[x]<<", selling @ $"<<intDrugArray[cnt]<<"\n";
intSell[cnt2]=cnt;
cnt2++;
}
}
cnt++;
}

cout<<"\nSelect Drug to Sell (0 to cancel): "<<strChoice<<"\n";

cout<<"\nQuantity (0 to cancel): ";
cin>>strQuant;

//if it's a letter send it to the invalid choice menu
if (atoi(strQuant.c_str())==0 && strQuant !="0")
strQuant="9999";
}

//if the cancel value is entered return to the city
if (atoi(strQuant.c_str())==0 && strQuant=="0")
goto City;

//empty out inv of the drugs sold and update related variables
for(i=0;i<=11;i++)
{
if(strInvArray==strDrugArray[intSell[atoi(strChoice.c_str())]])
{
profile.Space=profile.Space+atoi(strQuant.c_str());
profile.Cash=profile.Cash+(atoi(strQuant.c_str())*intDrugArray[intSell[atoi(strChoice.c_str())]]);
if(atoi(strQuant.c_str())<intQuantArray)
{
intQuantArray=intQuantArray-atoi(strQuant.c_str());
}
else
{
intQuantArray=0;
intInvArray=0;
strInvArray=" ";
}
i=12;
}
}

//an impossible if so that this code can only be reached with the goto
if(intGunPrice==9999)
{
Sell_Gun:
profile.Cash=profile.Cash+intGunPrice;
profile.Gun="NONE";
profile.GunRate=0;
}

//return to the city
City:
CityOperations(false);

//reverts back to old colors
SetConsoleColors(hConsole, 15, 0);
}



that's teh sell drugs function but you mostly need the full code posted above to see what is wrong.

-Lordoftools

Share this post


Link to post
Share on other sites
since im going to bootcamp (navy) on weds the 31st im posting my final issue with my code and going to pray for the best.

Everyonce in a while when you try to buy something (ie. ludes @ $10 each) and you want to buy lets say 4 of them with your current $40 (this should work) it won't let you. It would allow something like 3 or less but not the max and sometimes it's more than just the upper end number it could be the top few numbers. (CAN'T STRESS THIS ENOUGH: this bug doesn't not happen all the time nor most of the time which is why im having such trouble finding the error).

The buying functions are posted below please reference the full source code in the previous posts:

[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);
string strAmt;

//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 (0 to cancel): ";
cin>>strAmt;

while (((atoi(strAmt.c_str())*Price)>profile.Cash) || (atoi(strAmt.c_str())>profile.Space))
{
//print menu
system("cls");
PrintStats();
//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
SetConsoleColors(hConsole, 10, 0);
cout<<"You don't have enough money or enough space for that much "<<Drug<<"!\n\n";
cout<<"How much "<<Drug<<" you want? ($"<<Price<<" each)"<<endl;
cout<<"Quantity (0 to cancel): ";
cin>>strAmt;
}

//updates the space in your inv
profile.Space=profile.Space-atoi(strAmt.c_str());
profile.Cash=profile.Cash-(atoi(strAmt.c_str())*Price);

//fills the drug into the available array slot
if (atoi(strAmt.c_str()) !=0)
{
//add it to drugs that are alrdy there
for (i=0; i<=11; i++)
{
if (strInvArray==Drug)
{
//divides the two costs out so that it accurately represents how much you paid for everything
intInvArray=((intQuantArray*intInvArray)+(Price*atoi(strAmt.c_str())))/(intQuantArray+atoi(strAmt.c_str()));
intQuantArray=intQuantArray+atoi(strAmt.c_str());
goto End_If;
}
}
//add it to empty spot if drug wasn't found in inv
for (i=0; i<=11; i++)
{
if (intInvArray==0)
{
strInvArray=Drug;
intInvArray=Price;
intQuantArray=atoi(strAmt.c_str());
i=12;
}
}
}
End_If:

//reverts back to old colors
SetConsoleColors(hConsole, 10, 0);

BuyDrugsMenu();
}

void CheckWhichDrug(char chrDrug, int intTemp[12])
{
//Function level Declarations
HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0);
char chrChoice;

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

switch (chrDrug)
{
case 'h':
cout<<"Did you want HASHISH or HERION?\n\n";
cout<<"1. HASHISH.\n";
cout<<"2. HERION.\n";
cout<<"Selection (0 to cancel): ";
//await choice
cin>>chrChoice;

switch (chrChoice)
{
case '0':
BuyDrugsMenu();
case '1':
BuyingDrugs("HASHISH", intTemp[3]);
break;
case '2':
BuyingDrugs("HERION", intTemp[4]);
break;
default:
goto RePick;
break;
}
break;

case 'p':
cout<<"Did you want PCP or PEYOTE?\n\n";
cout<<"1. PCP.\n";
cout<<"2. PEYOTE.\n";
cout<<"Selection (0 to cancel): ";
//await choice
cin>>chrChoice;

switch (chrChoice)
{
case '0':
BuyDrugsMenu();
case '1':
BuyingDrugs("PCP", intTemp[8]);
break;
case '2':
BuyingDrugs("PEYOTE", intTemp[9]);
break;
default:
goto RePick;
break;
}
break;

case 's':
cout<<"Did you want SHROOMS or SPEED?\n\n";
cout<<"1. SHROOMS.\n";
cout<<"2. SPEED.\n";
cout<<"Selection (0 to cancel): ";
//await choice
cin>>chrChoice;

switch (chrChoice)
{
case '0':
BuyDrugsMenu();
case '1':
BuyingDrugs("SHROOMS", intTemp[10]);
break;
case '2':
BuyingDrugs("SPEED", intTemp[11]);
break;
default:
goto RePick;
break;
}
break;
}
}

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

//initialize function level declarations
for (i=0;i<=6;i++)
boolDrugPresent=false;

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 ((strDrugArray !=" ") && (intDrugArray<=profile.Cash))
goto SkipFor;
}
cout<<"Your broke! Go somewhere else or sell some of your product to make up the $$$.\n\n";
cout<<"Press any key to return to \""<<loc.Name<<"\"";
getch();
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 (strDrugArray=="ACID")
{
cout<<"A. ACID - $"<<intDrugArray<<endl;
intTemp[1]=intDrugArray;
boolDrugPresent[0]=true;
}
else if (strDrugArray=="COCAINE")
{
cout<<"C. COCAINE - $"<<intDrugArray<<endl;
intTemp[2]=intDrugArray;
boolDrugPresent[1]=true;
}
else if (strDrugArray=="HASHISH")
{
cout<<"H. HASHISH - $"<<intDrugArray<<endl;
intTemp[3]=intDrugArray;
oneH=true;
}
else if (strDrugArray=="HERION")
{
cout<<"H. HERION - $"<<intDrugArray<<endl;
intTemp[4]=intDrugArray;
twoH=true;
}
else if (strDrugArray=="LUDES")
{
cout<<"L. LUDES - $"<<intDrugArray<<endl;
intTemp[5]=intDrugArray;
boolDrugPresent[2]=true;
}
else if (strDrugArray=="MDA (Ecstasy)")
{
cout<<"M. MDA (Ecstasy) - $"<<intDrugArray<<endl;
intTemp[6]=intDrugArray;
boolDrugPresent[3]=true;
}
else if (strDrugArray=="OPIUM")
{
cout<<"O. OPIUM - $"<<intDrugArray<<endl;
intTemp[7]=intDrugArray;
boolDrugPresent[4]=true;
}
else if (strDrugArray=="PCP")
{
cout<<"P. PCP - $"<<intDrugArray<<endl;
intTemp[8]=intDrugArray;
oneP=true;
}
else if (strDrugArray=="PEYOTE")
{
cout<<"P. PEYOTE - $"<<intDrugArray<<endl;
intTemp[9]=intDrugArray;
twoP=true;
}
else if (strDrugArray=="SHROOMS")
{
cout<<"S. SHROOMS - $"<<intDrugArray<<endl;
intTemp[10]=intDrugArray;
oneS=true;
}
else if (strDrugArray=="SPEED")
{
cout<<"S. SPEED - $"<<intDrugArray<<endl;
intTemp[11]=intDrugArray;
twoS=true;
}
else if (strDrugArray=="WEED")
{
cout<<"W. WEED - $"<<intDrugArray<<endl;
intTemp[12]=intDrugArray;
boolDrugPresent[5]=true;
}
}

//print gun options and determine price with trade-in value of old gun
if (boolGun==true)
{
boolDrugPresent[6]=true;

if (profile.Gun=="BARETTA")
TradeIn=1500;
if (profile.Gun==".38SPEC")
TradeIn=1725;
if (profile.Gun=="RUGER")
TradeIn=1450;
if (profile.Gun=="SATNIGHTSPEC")
TradeIn=1600;
if (profile.Gun=="NONE")
TradeIn=0;

switch (intGun)
{
case 1:
cout<<"\nG. Baretta (Reduces police presence to 13%, Current Rating="<<20-profile.GunRate<<"%) - $3000."<<endl;
cout<<"\t$"<<3000-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
intTemp[13]=3000-TradeIn;
buyGun="Baretta";
break;
case 2:
cout<<"\nG. .38 Special (Reduces police presence to 7%, Current Rating="<<20-profile.GunRate<<"%) - $3500."<<endl;
cout<<"\t$"<<3500-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
intTemp[13]=3500-TradeIn;
buyGun=".38 Special";
break;
case 3:
cout<<"\nG. Ruger (Reduces police presence to 15%, Current Rating="<<20-profile.GunRate<<"%) - $2900."<<endl;
cout<<"\t$"<<2900-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
intTemp[13]=2900-TradeIn;
buyGun="Ruger";
break;
case 4:
cout<<"\nG. Saturday night Special (Reduces police presence to 10%, Current Rating="<<20-profile.GunRate<<"%) - $3100."<<endl;
cout<<"\t$"<<3100-TradeIn<<" after the $"<<TradeIn<<" discount for trading in your current gun.\n";
intTemp[13]=3100-TradeIn;
buyGun="Saturday night Special";
break;
}
}
cout<<"\nSelection (0 to cancel): ";
cin>>chrChoice;

//check for duplicate letters and proceed with purchase
if ((chrChoice=='A' || chrChoice=='a') && boolDrugPresent[0]==true)
{
BuyingDrugs("ACID", intTemp[1]);
}
else if (chrChoice=='0')
{
CityOperations(false);
}
else if ((chrChoice=='C' || chrChoice=='c') && boolDrugPresent[1]==true)
{
BuyingDrugs("COCAINE", intTemp[13]);
}
else if ((chrChoice=='G' || chrChoice=='g') && boolDrugPresent[6]==true)
{
BuyingGun(buyGun, intTemp[13]);
}
else if ((chrChoice=='M' || chrChoice=='m') && boolDrugPresent[3]==true)
{
BuyingDrugs("MDA (Ecstasy)", intTemp[6]);
}
else if ((chrChoice=='L' || chrChoice=='l') && boolDrugPresent[2]==true)
{
BuyingDrugs("LUDES", intTemp[5]);
}
else if ((chrChoice=='O' || chrChoice=='o') && boolDrugPresent[4]==true)
{
BuyingDrugs("OPIUM", intTemp[7]);
}
else if ((chrChoice=='W' || chrChoice=='w') && boolDrugPresent[5]==true)
{
BuyingDrugs("WEED", intTemp[12]);
}
//for duplicate H's
else if ((chrChoice=='H' || chrChoice=='h') && (oneH==true && twoH==true))
{
CheckWhichDrug('h', intTemp);
}
//for none duplicate
else if ((chrChoice=='H' || chrChoice=='h') && (oneH==false || twoH==false))
{
for (i=0; i<=11; i++)
{
if (strDrugArray=="HASHISH")
{
BuyingDrugs("HASHISH", intTemp[3]);
i=12;
}
if (strDrugArray=="HERION")
{
BuyingDrugs("HERION", intTemp[4]);
i=12;
}
}
}
//for duplicate P's
else if ((chrChoice=='P' || chrChoice=='p') && (oneP==true && twoP==true))
{
CheckWhichDrug('p', intTemp);
}
//for none duplicate
else if ((chrChoice=='P' || chrChoice=='p') && (oneP==false || twoP==false))
{
for (i=0; i<=11; i++)
{
if (strDrugArray=="PCP")
{
BuyingDrugs("PCP", intTemp[8]);
i=12;
}
if (strDrugArray=="PEYOTE")
{
BuyingDrugs("PEYOTE", intTemp[9]);
i=12;
}
}
}
//for duplicate S's
else if ((chrChoice=='S' || chrChoice=='s') && (oneS==true && twoS==true))
{
CheckWhichDrug('s', intTemp);
}
//for none duplicate
else if ((chrChoice=='S' || chrChoice=='s') && (oneS==false || twoS==false))
{
for (i=0; i<=11; i++)
{
if (strDrugArray=="SHROOMS")
{
BuyingDrugs("SHROOMS", intTemp[10]);
i=12;
}
if (strDrugArray=="SPEED")
{
BuyingDrugs("SPEED", intTemp[11]);
i=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);

//go back to city
CityOperations(false);
}

void BuyingGun(string Gun, int Price)
{
//Function level Declarations
HANDLE hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0);

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

if (Price>profile.Cash)
{
//print menu
system("cls");
PrintStats();
//make stats 'GREEN' (10) with 'blk bg' (0) [menu std color]
SetConsoleColors(hConsole, 10, 0);
cout<<"You don't have enough money for the "<<Gun<<"!\n\n";
cout<<"Press any key to return to the Buy Drugs menu."<<endl;
getch();
goto Back;
}

//updates info
profile.Cash=profile.Cash-Price;
if (Gun=="Saturday night Special")
{
profile.Gun="SATNIGHTSPEC";
profile.GunRate=10;
}
if (Gun=="Baretta")
{
profile.Gun="BARETTA";
profile.GunRate=13;
}
if (Gun==".38 Special")
{
profile.Gun=".38SPEC";
profile.GunRate=7;
}
if (Gun=="Ruger")
{
profile.Gun="RUGER";
profile.GunRate=5;
}

//reverts back to old colors
SetConsoleColors(hConsole, 10, 0);

Back:
BuyDrugsMenu();
}



-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!