I was attempting to make a simple pokemon text game in c++.
I created a class for pokemon, and then in my pokemain.cpp tried outputting hp from charmander.
When i try running my pokemonmain.cpp, it says charmander was not declared. Im sure this is a dumb question, but I cant find an answer to it.
Here is my code.
//class named stats
#include <iostream>
using namespace std;
class pokemon
{
int health, damage;
public:
pokemon (int,int);
int hp()
{
return (health);
}
int dmg()
{
return (damage);
}
};
pokemon::pokemon (int hp, int dmg)
{
health = hp;
damage = dmg;
pokemon charmander (25,3);
pokemon bulbasaur (20,4);
pokemon squirtle (30,2);
cout<<" Charmander has "<<charmander.hp()<<" hp and "<<charmander.dmg()<<" damage.\n";
cout<<" Bulbasaur has "<<bulbasaur.hp()<<" hp and "<<bulbasaur.dmg()<<" damage.\n";
cout<<" Squirtle has "<<squirtle.hp()<<" hp and "<<squirtle.dmg()<<" damage.\n";
}
//pokemain.cpp
#include <iostream>
#include "stats.h"
using namespace std;
int main()
{
cout<<charmander.hp();
return 0;
}
The variables
charmander,bulbausarandsquirtleare being declared inside the constructor. Put them in your main and it should work.