Problem with basic txt program

Started by
5 comments, last by TommySauder 18 years, 7 months ago
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
Advertisement
It looks like you haven't defined the body of the function menu().
my siteGenius is 1% inspiration and 99% perspiration
I have though (I changed the prototype in main from int menu(); to int menu(int a);)

Same problem, and the body is definately there....
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;}
Well, take a careful look at this:
class alpha{  int betaprivate:  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.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

fixed the class problem... that must have been a sleepy mistake.

couple more problems that im trying to work out though.
fixed all the little quirks... I wrote all that in 10 mins to get it all out of my head, long day today too so must have been a bit tired... all fixed thanks.

This topic is closed to new replies.

Advertisement