Needing help to reduce the damge_bar of the ship (Beginner)
I'm needing help with this code. The idea is that I has a ship and if I hit it with a shoot the health bar will go from 100 and down until it is 0 then the ship doesn't exists anymore. But I have problem while saying to the program that if it was a hit do "health_bar -= 10" I know what the problem are but not how to fix it. Is it anyone that has another idea of doing this or how to do this?. Please help!.
Code:
#include <iostream>
#include <cstddef>
#include <cstdlib>
using namespace std;
class Ships
{
public:
int health_bar;
string name;
};
Ships* getNewShip()
{
Ships *p_ship = new Ships;
p_ship->name = " ";
p_ship->health_bar = 0;
return p_ship;
}
void Ship_1()
{
Ships *p_ship;
p_ship->name = "Xtr-30";
p_ship->health_bar += 100;
cout << "Name: " << p_ship->name << endl;
cout << "Health: " << p_ship->health_bar << endl;
}
int main()
{
bool menu = false;
while (menu == false)
{
system("CLS");
int input;
cout << "Attack ship: ";
cin >> input;
if (input == 1)
{
Ships* getShip = getNewShip();
Ship_1(getShip);
system("PAUSE");
}
}
return 0;
}