Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Pointer Error

$
0
0
While I am getting no C++ compilation errors or runtime errors, my visual studio is having trouble reading the adress for my enemy pointer. If you could tell me what I am doing wrong it would be greatly appreciated.

#include "Armor.h"
#include "Character.h"
#include "Enemy.h"
#include "Weapon.h"
#include "Random.h"

#include <iostream>
#include <string> 

using namespace std; 
bool go = true; 

Enemy *enemy = 0; 
bool fight = true; 

void Attack()
{
	while(fight = true)
	{
		int z = Random(0, Main.Level);

		if(z = 0)
			Enemy *enemy = new Enemy("Chicken", 50, 0, 100, 4, 12, 32); 
		else if(z = 1)
			Enemy *enemy = new Enemy("Goblin", 67, 0, 200, 8, 24, 36); 

		cout << "You are fighting a " <<  enemy->Name << endl; 
		cout << "1) Attack " << endl; 
		int choice; 
		cin >> choice; 

		if(choice = 1)
		{
			cout << "You attack it with a " << Main.weapon->Name << endl; 
			int damage = Random (0, Main.weapon->Damage); 
			int total = (damage - (1/3 * enemy->Armor)); 
			enemy->Health = enemy->Health - total; 
	
			if(enemy->Health <= 0)
			{
				cout << "You killed the enemy" << endl; 
				cout << "You earned " << enemy->ExpReward << " EXP! " << endl; 
				Main.Gold = Main.Gold + enemy->GoldReward;
				Main.Experience = Main.Experience + enemy->ExpReward; 
				bool fight = false; 
			}
		}
		else 
		{
			int damage = Random(0, enemy->Damage); 
			Main.Health = Main.Health - damage; 
	
			if(Main.Health <= 0)
			{
				cout << "I'm Sorry.  You died in battle! " << endl; 
				bool fight = false; 
			}
		}
	}

delete enemy; 
enemy = 0; 
}

int main()
{
	Character Main; 
	Main.Set("George", 100, 100, 0, 0, 1, 0); 
	Main.weapon = new Weapon("Bronze Dagger", 48, 100); 

	cout << "Welcome to Test 1" << endl; 
	cout << "Begin" << endl; 	
	while(go = true)
	{
		Attack(); 
		return 0; 
	}

	delete Main.weapon; 
	Main.weapon = 0; 
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>