Hi everybody,
i am creating my very first little game now, it is just the beginning of the game...however i found an error while compiling:
'obj' : undeclare identifier
it was in line 85.
Here is my program....:
ThanksCode:#include <iostream.h> #include <fstream.h> #include <stdlib.h> #include <string.h> typedef char string[25]; class Digimon { private: string name; int health; int stamina; public: Digimon(string="nothing", int=0, int=0); friend ostream& operator<<(ostream& out, Digimon& digi); friend void Play(Digimon, Digimon); void AttLost(int); }; Digimon::Digimon(string n, int hp, int sp) { strcpy(name,n); health=hp; stamina=sp; } ostream& operator<<(ostream& out, Digimon& digi) { out<<"Your Digimon STATS"<<endl; out<<"Your Digimon : "<<digi.name<<endl; out<<"Your HP : "<<digi.health<<endl; out<<"Your SP : "<<digi.stamina<<endl; return out; } void Play(Digimon enem, Digimon you) { while ((enem.health==0)||(you.health==0)) { cout<<you.name<<" ATTACK!!!"<<endl; enem.AttLost(2); cout<<enem.name<<" WOOF!!"<<endl; you.AttLost(1); } if (enem.health<=0) { cout<<"YOU WIN!!"; } else cout<<"YOU LOST!!"; } void Digimon::AttLost(int lostHP) { health=health-lostHP; } void ChooseCharacter(int&); //Function prototype int main() { int ans; ChooseCharacter(ans); if (ans==1) { Digimon obj("Guilmon", 25, 10); cout<<obj; } else if (ans==2) { Digimon obj("Renamon", 20, 20); cout<<obj; } else { Digimon obj("Terriermon", 22, 15); cout<<obj; } cout<<"You encounter a crazy stupid yet powerful digiMONSTER!!"<<endl; cout<<"IT is RUBYMON!!!"<<endl; Digimon enemy1("Rubymon", 8, 4); Play(enemy1,obj); //LINE 85!!! ERROR HERE!! cout<<enemy1; system("PAUSE"); return 0; } void ChooseCharacter(int& ans) { cout<<"Welcome to The Digital World"<<endl; cout<<"Please choose your favorite digimon to travel with you!"<<endl; cout<<"1.Guilmon"<<endl; cout<<"2.Renamon"<<endl; cout<<"3.Terriermon"<<endl; cin>>ans; }



LinkBack URL
About LinkBacks


