I've been trying to do a really easy game here, the thing is that the when a player reaches 0, it just keep going to -5 and such like. WHat's wrong?
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main ()
{
srand(time(0));
int player1 = 100;
int player2 = 100;
char player1Name;
char player2Name;
int PlayerTurn(1);
int Attack;
bool GameOver(false);
bool GameWin(false);
do {
cout << "it's player" << PlayerTurn << "'s turn" << "do you want to attack with a high risk or a low risk attack? low risk = type1 high risk = type2" << endl;
cout << "Attck with type >>";
cin >> Attack;
if(Attack == 1) {
double hit = rand() % 31 + 10;
if(PlayerTurn == 1){
player2-hit;
cout << "you took " << hit << " points from player2" << endl;
cout << "\nplayer2 has " << player2 << " points left\n" << endl;
}
else {
player1-hit;
cout << "you took " << hit << " points from player1 " << endl;
cout << "\nplayer1 has " << player1 << " points left\n" << endl;
}
}
if(Attack == 2){
double maxhit = rand() % 41 + 18;
double iff = rand() % 2 + 1;
if(iff == 1){
cout << "you failed" << endl;
}
if(iff == 2) {
if(PlayerTurn == 1){
player2-maxhit;
cout << "you took " << maxhit << " points from player2" << endl;
cout << "\nplayer2 has " << player2 << " points left\n" << endl;
}
else {
player1-maxhit;
cout << "you took " << maxhit << " points from player1" << endl;
cout << "\nplayer1 has " << player1 << " points left\n" << endl;
}
}
if(player1 <= 0) {
cout << "game over player1 lost, and player2 won!" << endl;
GameOver = true;
}
if(player2 <= 0) {
cout << "game over player2 lost, and player1 won!" << endl;
GameOver = true;
}
}
if(GameOver){
cout << "it's time to end this, bye!!";
}
if(PlayerTurn == 1) {
PlayerTurn = 2;
}
else {
PlayerTurn = 1;
}
} while(!GameOver);
}