0

Can you help me fix my PIG program? Please tell me how I'm wrong and show me :)

Here it is: #include <iostream> #include <string> using namespace std; class pig{ private: string name; double health20mx; int use; string valTa; public: int attack; pig(string nameC, double health20mxC, int useC) { setName(nameC); setHealth(health20mxC); setUse(useC); } void setName(string nameB) { name = nameB; } string getName() { return name; } void setHealth(double health20mxB) { health20mx = health20mxB; } double getHealth() { return health20mx; } void attackPig(int attack) { health20mx -= attack; } void healPig(int heal) { health20mx += heal; } int setUse(int useB) { use = useB; } string getUse() { if (use==0) { valTa = "fat take"; }else if (use==1) { valTa = "herder"; }else if (use==2) { valTa = "wild boar without attacks"; }else if (use==3) { valTa = "dangerous boar"; }else { valTa = "food"; } } bool battlePig(int damageB,double healthD){ while (healthD <= 0 || health20mx <= 0) { healthD -= attack; if(healthD <= 0) { return true; break; } health20mx -= damageB; if(health20mx <= 0) { return false; break; } } } }; int main() { pig Tyler("Tyler", 1, 3); Tyler.attack = 4; pig Hitter("Hitter", 10, 5); Hitter.attack = 6; int EDam = Hitter.attack; double EHel = Hitter.getHealth(); bool tylerWonQ = Tyler.battlePig(EDam, EHel); cout << "Did Tyler win? " << tylerWonQ << endl; return 0; }

8th Nov 2016, 12:17 PM
Trey
1 Antwort
0
#include <iostream> #include <string> using namespace std; class pig{ private: string name; double health20mx; int use; string valTa; public: int attack; pig(string name, double health20mx, int use):name(name),health20mx(health20mx),use(use){} string getName() { return name; } double getHealth() { return health20mx; } void attackPig(int attack) { health20mx -= attack; } void healPig(int heal) { health20mx += heal; } string getUse() { if (use==0) { valTa = "fat take"; }else if (use==1) { valTa = "herder"; }else if (use==2) { valTa = "wild boar without attacks"; }else if (use==3) { valTa = "dangerous boar"; }else { valTa = "food"; } } bool battlePig(int damageB,double healthD){ while (healthD <= 0 || health20mx <= 0) { healthD -= attack; if(healthD <= 0) { return true; break; } health20mx -= damageB; if(health20mx <= 0) { return false; break; } } } }; int main() { pig Tyler("Tyler", 1, 3); Tyler.attack = 4; pig Hitter("Hitter", 10, 5); Hitter.attack = 6; int EDam = Hitter.attack; double EHel = Hitter.getHealth(); bool tylerWonQ = Tyler.battlePig(EDam, EHel); cout << "Did Tyler win? " <<boolalpha<< tylerWonQ << endl; return 0; }
8th Nov 2016, 12:55 PM
மனோஜ்குமார் பழனிச்சாமி
மனோஜ்குமார் பழனிச்சாமி - avatar