#ifndef _PLAYER_H_
#define _PLAYER_H_
class Player
{
private:
int health;
int mana;
int exp;
int level;
public:
//Getter functions
int getHealth()const {return health;}
int getMana()const {return mana;}
int getExp()const {return exp;}
int getLevel()const {return level;}
//Setter functions
void setHealth(int h) {h = health;}
void setMana(int m) {m = mana;}
void setExp(int e) {e = exp;}
void setLevel(int l){l = level;}
//Normal Functions
void player();
}player;
#endif _PLAYER_H_
main.h
1 2 3 4 5 6 7 8 9 10 11
/****************************************************************
*
* * This, the main class, handles general things
*
****************************************************************/
// Subsitute Variables for Class Player
int h;
int m;
int e;
int l;
//=================================Break===================================//
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <string>
#include "main.h"
#include "player.h"
usingnamespace std;
int main()
{
cout << "Input the value of your health : ";
cin >> h;
player.setHealth(h);
cout << "\n The value of your health is ";
cout << player.getHealth();
return 0;
}
If you compile this, you will see that this code has a serious problem: The getter function won't update, therefor I do not get the actual value entered by the user. I don't know what's wrong, can you guys please help me?
You changed the value of h to the value of health
this is how it should be done void setHealth(int h) {health = h;}
you should correct all setter functions