Jump to content
  • Advertisement
Sign in to follow this  
TommySauder

Problem with basic txt program

This topic is 4668 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, 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
Advertisement
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
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.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!