Archived

This topic is now archived and is closed to further replies.

Um something is wrong with my equation?

This topic is 5154 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

I have an equation that is supposed to set the enemys health after the player attacks him it looks like this:
void CPlayer::attack(CMonster *monster){
	monster->setMonsterHealth((monster->getMonsterHealth() + (.05 * monster->getMonsterDefense())) - (getStrength()));
	cout<<monster->getMonsterHealth();
}
MonHealth + (.05 * monDef) - playerstrngth It should do this: 100 + (.05 * 100) - 60. but when it runs i get 85 as the answer... What am i doin wrong? Thanks you guys have been really great to me.
Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|

Share this post


Link to post
Share on other sites
yeah the strength isn''t comming out right... I cant see why but its printing out the strength as 20. It should print out as 60.
Here''s full source...

//Copyright 2003 Cory Fisher

#include<iostream> //For cin,cout

#include<string> //For string use

#include<stdio.h> //For standard io

using namespace std; //Dont know why just everyone says you should

string nameSet(); //Forward declaration of nameSet()

class CMonster;
class CPlayer;
class Barbarian;
class Necromancer;
class CPlayer{ //Base Player Class

private:
int playerHealth; //Begin of self explanatory section

int playerMaxHealth;
int playerMana;
int playerMaxMana;
int playerLevel;
int playerStrength;
int playerSpeed;
int playerDefense;
int playerSkill;
string playerName;
string playerClass; //End of self explanatory section

public:
string skill[10];
CPlayer():
playerHealth(0),
playerMaxHealth(0),
playerMana(0),
playerMaxMana(0),
playerLevel(1),
playerStrength(0),
playerSpeed(0),
playerDefense(0),
playerSkill(1),
playerName(""),
playerClass("
")
{
}
int getHealth(){ //Begin Self Explanatory

return playerHealth;
}
int getMaxHealth(){
return playerMaxHealth;
}
int getMana(){
return playerMana;
}
int getMaxMana(){
return playerMaxMana;
}
int getLevel(){
return playerLevel;
}
int getStrength(){
return playerStrength;
}
int getSpeed(){
return playerSpeed;
}
int getDefense(){
return playerDefense;
}
int getSkill(){
return playerSkill;
}
string getName(){
return playerName;
}
string getClass(){
return playerClass;
}
void setHealth(int newhealth){
playerHealth = newhealth;
}
void setMaxHealth(int newmaxhealth){
playerMaxHealth = newmaxhealth;
}
void setMana(int newmana){
playerMana = newmana;
}
void setMaxMana(int newmaxmana){
playerMaxMana = newmaxmana;
}
void setLevel(int newlevel){
playerLevel = newlevel;
}
void setStrength(int newstrength){
playerStrength = newstrength;
}
void setSpeed(int newspeed){
playerSpeed = newspeed;
}
void setDefense(int newdefense){
playerDefense = newdefense;
}
void setSkill(int newskill){
playerSkill = newskill;
}
void setName(string newname){
playerName = newname;
}
void setClass(string newclass){
playerClass = newclass;
} //End of Self Explanatory

void printBaseInfo(){ //Prints the things that are common to all characters

cout<<"
Name: "<<playerName<<endl;
cout<<"
Level: "<<playerLevel<<endl;
}
void printSkills(){ //Prints all skills known

cout<<"
Skills Learned: ";
for(int i = 1; i < 11; i++){
if(playerSkill < i){
break;
}
if(playerSkill > i){
cout<<skill[i]<<"
, ";
}
if(playerSkill == i){
cout<<skill[i]<<endl;
}

}
}
void attack(CMonster *monster);

};
class Barbarian : public CPlayer{ //Derived barbarian class

public:
Barbarian(){ //Default constructor set to what i like for a Barbarian

setHealth(100);
setMaxHealth(100);
setMana(20);
setMaxMana(20);
setStrength(60);
setSpeed(40);
setDefense(60);
setName(nameSet());
setClass("
Barbarian");
initSkills();
}
void printInfo(){ //Prints not always same stuff as other characters.

system("
cls");
cout<<"
Class: "<<getClass()<<endl;
printBaseInfo();
cout<<"
Health: "<<getHealth()<<"/"<<getMaxHealth()<<endl;
cout<<"
Mana: "<<getMana()<<"/"<<getMaxMana()<<endl;
cout<<"
Strength: "<<getStrength()<<endl;
cout<<"
Speed: "<<getSpeed()<<endl;
cout<<"
Defense: "<<getDefense()<<endl;
printSkills();
}
void initSkills(){ //Initialize barbarians skills

skill[0] = "
Bruise";
skill[1] = "
Bash";
skill[2] = "
Crush";
skill[3] = "
Bang";
skill[4] = "
Break";
skill[5] = "
Boom";
skill[6] = "
Crack";
skill[7] = "
Shatter";
skill[8] = "
Destroy";
skill[9] = "
Annihilate";
}

};
class Necromancer : public CPlayer{ //Derived necromancer class

public:
Necromancer(){ //Default constructor stats i want for a necromancer

setHealth(100);
setMaxHealth(100);
setMana(60);
setMaxMana(60);
setStrength(20);
setSpeed(60);
setDefense(40);
setName(nameSet());
setClass("
Necromancer");
initSkills();
}
void printInfo(){ //Same as above

system("
cls");
cout<<"
Class: "<<getClass()<<endl;
printBaseInfo();
cout<<"
Health: "<<getHealth()<<"/"<<getMaxHealth()<<endl;
cout<<"
Mana: "<<getMana()<<"/"<<getMaxMana()<<endl;
cout<<"
Strength: "<<getStrength()<<endl;
cout<<"
Speed: "<<getSpeed()<<endl;
cout<<"
Defense: "<<getDefense()<<endl;
printSkills();
}
void initSkills(){ //Same as above cept its for necromancer

skill[0] = "
Fire";
skill[1] = "
Flame";
skill[2] = "
Burn";
skill[3] = "
Big Burn";
skill[4] = "
Blaze";
skill[5] = "
Firestorm";
skill[6] = "
Forest Fire";
skill[7] = "
Flame of Demon";
skill[8] = "
Smoke Rings";
skill[9] = "
Hell Fire";
}
}player;
class CMonster{
private:
int health;
int maxhealth;
int defense;
int speed;
int strength;
public:
CMonster(){
health = 100;
maxhealth = 100;
defense = 100;
speed = 100;
strength = 100;
}
int getMonsterHealth(){
return health;
}
void setMonsterHealth(int newhealth){
health = newhealth;
}
int getMonsterDefense(){
return defense;
}
}big;
int chartype;
void getCharacterType(){
cout<<"
1) Barbarian\n";
cout<<"
2) Necromancer\n";
cout<<"
What kind of character would you like to be?";
cin>>chartype;
}

void main(){ //Main Does nothing haven''t started actual game coding yet

getCharacterType();
player.attack(&big);
cout<<endl;
player.attack(&big);
}
string nameSet(){ //It gets the name from the user when the constructor for

string charname; //the class is called;

cout<<"
Enter a name:";
cin>>charname;
return charname;
}
void CPlayer::attack(CMonster *monster){
cout<<monster->getMonsterHealth()<<endl;
cout<<monster->getMonsterDefense()<<endl;
cout<<getStrength()<<endl;
monster->setMonsterHealth((monster->getMonsterHealth() + (.050 * monster->getMonsterDefense())) - (getStrength()));

}

Thanks again.



Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|

Share this post


Link to post
Share on other sites
keep putting more couts throughout your code to print out the strength and different stages (just post construction for example). this is simple debugging, use your brain to try and figure it out.

Share this post


Link to post
Share on other sites
Whoops just a stupid mistake I was automatically thinking that since i picked a barbarian it would be using the barbarian... but it was using necromancer since thats the object i was creating... I must be getting tired.



Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|

Share this post


Link to post
Share on other sites