Sign in to follow this  
TommySauder

Problem with basic txt program

Recommended Posts

Ok, after attempting to review my basic skills at C++ (been about a year), I've run into a little trouble...
// classes

#include <iostream>

using namespace std;

class Weapons
{
public:
	int getDamage();
	void setDamage(int a);
private:
	int Damage;
};


class Items
{
public:
	void setAmount(int a);
	int getAmount();
private:
	int Amount;
};


class Enemy
{
public:
	void setDamage(int a);
	int getDamage();
	void setHealth(int a);
	int getHealth();
	void setMana(int a);
	int getMana();
private:
	int Damage;
	int Health;
	int Mana;
};


class Spells
{
public:
	void setDamage(int a);
	int getDamage();
private:
	int Damage;
};

class Hero
{
public:
	void setHealth(int a) { Health = a; }
	void setMana(int a) { Mana = a; }
	void setArmor(int a) { Armor = a; }
	int getHealth() { return Health; }
	int getMana() { return Mana; }
	int getArmor() { return Armor; }
private:
	int Health;
	int Armor;
	int Mana;
};


class Weapons::getDamage()
{
	return Damage;
}

class Weapons::setDamage(int a)
{
	Damage = int a;
}

class Items::getAmount()
{
	return Amount;
}

class Items::setAmount(int a)
{
	int Amount = int a;
}

class Enemy::getDamage()
{
	return Damage;
}

class Enemy::getHealth()
{
	return Health;
}

class Enemy::getMana()
{
	return Mana;
}

class Enemy::setDamage(int a)
{
	int Damage = int a;
}

class Enemy::setHealth(int a)
{
	int Health = int a;
}

class Enemy::setMana(int a)
{
	int Mana = int a;
}
	
class Spells::setDamage(int a)
{
	Damage = int a;
}

class Spells::getDamage()
{
	return Damage;
}
int menu()
{
	int choice;
	for (;;)
	{
		bool exit = false;
		cout << "Choose your class\n\n";

		cout << "(1)\tWarrior\n";
		cout << "(2)\tArcher\n";
		cout << "(3)\tMage\n";
		cin >> choice;

		switch (choice)
		{
		case 1:
			{
				cout << "You chose Warrior class\n";
				exit = true;
				break;
			}
		case 2:
			{
				cout << "You chose Archer class\n";
				// statements (class setup)
				exit = true;
				break;
			}
		case 3:
			{
				cout << "You chose Mage class\n";
				// statements (class setup)
				exit = true;
				break;
			}
		default:
			{
				cout << "Invalid choice, please choose again\n\n";
			}
		}

		if (exit==true)
			break;
	}

	return choice;
}
#include "combat.hpp"
#include "setup.hpp"

int menu();

int main()
{
	int answer;
	answer = menu();

	Weapons Warrior;
	Weapons Archer;
	Weapons Mage;

	Hero WarriorH;
	Hero ArcherH;
	Hero MageH;
	
	if (answer==1)
	{
		Warrior.setDamage(50);
		WarriorH.setArmor(200);
		WarriorH.setHealth(500);
		WarriorH.setMana(10);
	}

	if (answer==2)
	{
		Archer.setDamage(25);
		ArcherH.setArmor(50);
		ArcherH.setHealth(300);
		ArcherH.setMana(100);
	}

	if (answer==3)
	{
		Mage.setDamage(10);
		MageH.setArmor(25);
		MageH.setHealth(200);
		MageH.setMana(500);
	}		


	return 0;
}
It's not complete, I just ran into a compiler error and im clueless as to why... main.cpp(9) : error C2065: 'menu' : undeclared identifier

Share this post


Link to post
Share on other sites
Main.cpp(42) : fatal error C1004: unexpected end of file found


#include "combat.hpp"
#include "setup.hpp"

int main()
{
int answer;
answer = menu();

Weapons Hero;

Hero Stat;

if (answer==1)
{
Hero.setDamage(50);
Stat.setArmor(200);
Stat.setHealth(500);
Stat.setMana(10);
}

if (answer==2)
{
Hero.setDamage(25);
Stat.setArmor(50);
Stat.setHealth(300);
Stat.setMana(100);
}

if (answer==3)
{
Hero.setDamage(10);
Stat.setArmor(25);
Stat.setHealth(200);
Stat.setMana(500);
}

cout << "Damage: " << Hero.getDamage << "\n";
cout << "Health: " << Stat.getArmor << "\n";

return 0;
}

Share this post


Link to post
Share on other sites
Well, take a careful look at this:
class alpha
{
int beta
private:
void setBeta(int beta1);
int getBeta();
};

void alpha::setBeta(int beta1)
{
beta = beta1;
}

int alpha::getBeta()
{
return beta;
}
Compare it with your code. Then when you realize what is different about it make some changes and recompile and then reread the section on classes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this