0

Having trouble with my massively massive program.
It compiles but fails to execute.

The instruction at "0x00471a6a" referenced memory at "0x00000114". The memory could not be "read".

Here's my program. (IF YOU HAVE ANY SOLUTION FOR THE VARIABLES IT WOULD BE APPRETIATED!!!)

the cpp is attached

Edited by spartan118: n/a

Attachments
/* THIS PROGRAM IS INCOMPLETE!!
PLEASE DON'T CORRECT THE EMPTY FUNCTIONS!!
Thanks,
Spartan118*/
//---------------------
//Definitions
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LIGHTGREY 7
#define DARKGREY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTCYAN 11
#define LIGHTRED 12
#define LIGHTMAGENTA 13
#define YELLOW 14
#define WHITE 15
#define BLINK 128
//use setfchcol for txt colour
//use setchcol for background colour
//-----------------
#include <windows.h>
#include <string>
#include <iostream>
#include "H:\lvp\conio.h"
#include <stdio.h>
#include "H:\lvp\matrix.h"
#include "H:\profile\desktop\rawrr\lvp\vector.h"
#include "H:\profile\desktop\rawrr\lvp\random.h"
#include "H:\lvp\irrKlang-1.3.0\include\irrKlang.h"
using namespace irrklang;
using namespace std;

#pragma comment(lib, "H:\\lvp\\irrKlang-1.3.0\\irrKlang.lib")
void damagecalculation (string enemyHas, string playerHas, string playerhas, string enemy, string enemyhas, string Weapon, string Weapon2, 
	string object, string munition, string playeraction, int enemyHealth, int enemyArmour, int eShields, int playerShields, int	playerHealth,
	int	playerArmour, int pShields, string choosecharacter, int rounds, int mags, double enemyShields, double dmg, 
	double speed, double totaldamage, double totalshields, double totalShields, int ochch)
	{
		if ((enemyHas == "Armour")&&(enemyhas == "Armour"))
		{
			totaldamage = (enemyArmour - dmg);
			if (dmg > enemyArmour)
				totaldamage = (enemyArmour + enemyHealth - dmg);
			else if (enemyHealth > 100)
				enemyArmour = (enemyHealth - 100);
			if ((enemy == "Battle Droid")||(enemy == "Super Battle Droid")||(enemy == "Destroyer Droid")&&(munition == "Bullets")) //Munition types affect damage.
				totaldamage = (totaldamage - 100);
			else if ((enemy == "Battle Droid")||(enemy == "Super Battle Droid")||(enemy == "Destroyer Droid")&&(munition == "Plasma"))
			{
				totaldamage = (totaldamage + 100);
				cout << "The enemy has melted!!" << endl;
			}
		}			
	//************************
	
		if ((enemyHas == "Shields")&&(enemyhas == "Shields"))
		{
			totaldamage = (enemyShields - dmg); //Damage impacts shields before armour
			if ((enemyShields == 0)||(enemyShields < totaldamage)) //if the enemies shields are less than the total damage done
			{
				totaldamage = (enemyShields + enemyArmour - dmg); //Program adds armour to shield value and depletes armour
				if (enemyShields > eShields)
				{
					totalshields = (enemyShields - eShields);
					enemyShields = totalshields; //Shield value becomes remainder
				}
			}
		}
		if ((enemyArmour == 0)&&(enemyShields == 0)) //enemy death
		{
			totaldamage = (enemyHealth - dmg);
			if (enemyHealth == 0)
				cout << "Enemy Defeated." << endl;
		}
	//**************************

		if ((playerHas == "Armour")||(playerhas == "Armour"))
		{
			totaldamage = (playerArmour - dmg);
			if (dmg > playerArmour)	
			{
				totaldamage = (playerArmour + playerHealth - dmg);
				if (playerHealth > 100)
					playerArmour = (playerHealth - 100);
			}
		}
		if ((playerHas == "Shields")||(playerhas == "Shields"))
		{
			totaldamage = (playerShields - dmg); //Damage impacts shields before armour
			if ((playerShields == 0)||(playerShields < totaldamage)) //if the enemies shields are less than the total damage done
			{
				totaldamage = (playerShields + playerArmour - dmg); //Program adds armour to shield value and depletes armour
				if (enemyShields > eShields)
				{
					totalshields = (playerShields - pShields);
				 //Shield value becomes remainder
					totalshields = playerShields;
				}
			}
		}
	}
void combat (string enemyHas, string playerHas, string playerhas, string enemy, string enemyhas, string Weapon, string Weapon2, 
	string object, string munition, string playeraction, int enemyHealth, int enemyArmour, int eShields, int playerShields, int	playerHealth,
	int	playerArmour, int pShields, string choosecharacter, int rounds, int mags, double enemyShields, double dmg, 
	double speed, double totaldamage, double totalshields, double totalShields, int ochch, string WeaponHas)
{
	int X;
	int openfire;
	damagecalculation(enemyHas, playerHas, playerhas, enemy, enemyhas, Weapon, Weapon2,
			  object, munition, playeraction, enemyHealth, enemyArmour, eShields, playerShields, playerHealth,
			  playerArmour, pShields, choosecharacter, rounds, mags, enemyShields, dmg,
			  speed, totaldamage, totalshields,  totalShields, ochch);
	if (openfire==1)
	{
		cout << "Entering Combat!" << endl;
		Sleep(1500);
		cout << "Options:\n";
		cout << "----------\n";
		cout << "1. Fire once" << endl;
		if (WeaponHas == "2x Scope")
		{
			cout << "2. Scope-in" << endl;
			cout << "3. Fire x amount of times" << endl;
		}
		if (Weapon == "MA5C Assault Rifle")
			cout << "2. Fire x amount of clips" << endl;
		cin >> X;
	}
}

void Encounter (string enemyHas, string playerHas, string playerhas, string enemy, string enemyhas, string Weapon, string Weapon2, 
	string object, string munition, string playeraction, int enemyHealth, int enemyArmour, int eShields, int playerShields, int	playerHealth,
	int	playerArmour, int pShields, string choosecharacter, int rounds, int mags, double enemyShields, double dmg, 
	double speed, double totaldamage, double totalshields, double totalShields, int ochch)
{
	randomize();
	int enemychance = random(100) +1;
	if ((enemychance >= 1)||(enemychance < 26))
		enemy = "Super Battle Droid";
	else if ((enemychance >= 26)||(enemychance < 37))
		enemy = "Destroyer Droid";
	else if ((enemychance >= 37)||(enemychance < 41))
		enemy = "Jedi";
	else if ((enemychance >= 41)||(enemychance < 45))
		enemy = "Sith";
	else if ((enemychance >= 45)||(enemychance < 71))
		enemy = "Clone Trooper, Elite";
	else if ((enemychance >= 72)||(enemychance <= 100))
	{
		randomize();
		int rrk = random(100) +1;
		if((rrk >= 1)||(rrk < 51))
			enemy = "Battle Droid";
		else if((rrk >= 51)||(rrk <= 100))
			enemy = "Clone Trooper, Regular";
	}
}
void enemyStats(string enemyHas, string playerHas, string playerhas, string enemy, string enemyhas, string Weapon, string Weapon2, 
	string object, string munition, string playeraction, int enemyHealth, int enemyArmour, int eShields, int playerShields, int	playerHealth,
	int	playerArmour, int pShields, string choosecharacter, int rounds, int mags, double enemyShields, double dmg, 
	double speed, double totaldamage, double totalshields, double totalShields, int ochch)
{
	if (enemy == "Clone Trooper, Regular")
	{
		enemyShields = 25;
		eShields = 25;
		enemyArmour = 100;
		enemyHealth = 50;
		enemyHas = "Shields";
		enemyhas = "Armour";
		dmg = 15;
		speed = 25;
	}
	else if (enemy == "Clone Trooper, Elite")
	{
		enemyShields = 40;
		eShields = 40;
		enemyArmour = 105;
		enemyHealth = 75;
		enemyHas = "Shields";
		enemyhas = "Armour";
	}
	else if (enemy == "Battle Droid")
	{
		enemyShields = 0;
		eShields = 0;
		enemyArmour = 130;
		enemyHealth = 25;
		enemyHas = "Armour";
	}
	else if (enemy == "Jedi")
	{
		enemyShields = 0;
		eShields = 0;
		enemyArmour = 20;
		enemyHealth = 200;
		enemyHas = "Armour";
	}
	else if (enemy == "Sith")
	{
		enemyShields = 0;
		eShields = 0;
		enemyArmour = 10;
		enemyHealth = 210;
		enemyHas = "Armour";
	}
	Encounter(enemyHas, playerHas, playerhas, enemy, enemyhas, Weapon, Weapon2,
			  object, munition, playeraction, enemyHealth, enemyArmour, eShields, playerShields, playerHealth,
			  playerArmour, pShields, choosecharacter, rounds, mags, enemyShields, dmg,
			  speed, totaldamage, totalshields,  totalShields, ochch);
}

void CharandWep (string enemyHas, string playerHas, string playerhas, string enemy, string enemyhas, string Weapon, string Weapon2, 
	string object, string munition, string playeraction, int enemyHealth, int enemyArmour, int eShields, int playerShields, int	playerHealth,
	int	playerArmour, int pShields, string choosecharacter, int rounds, int mags, double enemyShields, double dmg, 
	double speed, double totaldamage, double totalshields, double totalShields, int ochch, string WeaponHas)
{
	char Z;
	int w;
	int W;
	cout << "Choose a primary weapon:\n----------";
	cout << "1. MA5C Assault Rifle\n";
	cout << "2. Plasma Rifle\n";
	cout << "3. Battle Rifle\n";
	cout << "4. Covenant Carbine\n";
	cin >> w;
	Sleep(1500);
	cout << "Choose a sidearm:\n----------";
	cout << "1. M6G Sidearm\n";
	cout << "2. Plasma Pistol\n";
	cin >> W;
	
	if (w == 1)
		Weapon = "MA5C Assault Rifle";
	else if (w == 2)
		Weapon = "Plasma Rifle";
	else if (w == 3)
		Weapon = "Battle Rifle";
	else if (w == 4)
		Weapon = "Covenant Carbine";
	if (W == 1)
		Weapon2 = "M6G Pistol";
	else if (W == 2)
		Weapon2 = "Plasma Pistol";

	if (Weapon == "MA5C Assault Rifle")
	{
		dmg = 30; mags = 12;
		speed = 40; rounds = 32;
		munition = "Bullets";
	}
	else if (Weapon == "Plasma Rifle")
	{
		dmg = 40; rounds = 100; mags = 1;
		speed = 30; munition = "Plasma";
	}
	
	else if (Weapon == "Battle Rifle")
	{
		dmg = 16; rounds = 25;
		speed = 25; mags = 4;
		munition = "Bullets";
		WeaponHas = "2x Scope";
	}
	else if (Weapon == "Covenant Carbine")
	{
		dmg = 25; rounds = 18;
		speed = 30; mags = 5;
		munition = "Radiation";
		WeaponHas = "2x Scope";
	}
	if (Weapon2 == "M6G Pistol")
	{
		dmg = 60; rounds = 8;
		speed = 32; mags = 5;
		munition = "Bullets";
		WeaponHas = "2x Scope";
	}
	else if (Weapon2 == "Plasma Pistol")
	{
		dmg = 40; rounds = 100;
		speed = 32; mags = 1;
		munition = "Plasma";
	}
	if (choosecharacter == "4")
	playerHealth = 100;
	playerArmour = 150;
	playerShields = 175;
	pShields = 175;
	playerHas = ("Shields");
	playerhas = ("Armour");
	Sleep(1500);
	cout << "You have:\n1. Chosen the Master Chief.\n2. Chose the " << Weapon << " as your primary weapon, and the " << Weapon2 << " as your sidearm.\n\nYour stats are as displayed.\n Health: " << playerHealth << "\nArmour: " << playerArmour << "\nShield Value: " << playerShields <<
4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rdrast
0

compile that program for debug then use your compiler's debugger to step through the program one line at a time until you find out where the error occurs. One of the most common errors to look for is buffer overruns and using uninitialized variables.

Edited by Ancient Dragon: n/a

0

I'm 100% sure all my variables are initialized (because of the fact I get no errors) and how do I use Visual C++ v6's debugger?

0

>>I'm 100% sure all my variables are initialized (because of the fact I get no errors)

There's a difference between declaring them and initializing them:

declared, but not initialized will not give a compiler error, but will still cause problem

int a;
cout << a; // <-- Uh oh, uninitialized
0

I'd start with just getting a proper main() going.
And passing so much around, you should at least use a structure. Blindly copy and pasting isn't the way to get to modular code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.