DO LOOP FOR GAME ERROR

hey guys just want to know how come i give a choice to play again but my program crashes and the numbers of hp,armor comeback negative? i want it to play the game again for a new fresh game.

HERE IS THE MAIN CODE -> http://cpp.sh/7n2ha
1
2
3
4
5
6
7
8
9
10
11
		} while (!win);



		cout << " do you want to play again ? (y/n)";
		cin >> answer;



	} while (toupper(answer) == 'Y');

Well somewhere between those two lines, you need to reset both players to their respective initial states.

Otherwise, you're just going to restart with one of them already dead.

This, again, every time you start a new game.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	// Class Select
	Player* playerOne = new UNITS(" UNSC ");
	Player* playerTwo = new UNITS(" COVENANT ");

	// Coin Toss to Determine Who Goes First
	Player *currentPlayer, *targetPlayer, *tempPlayer;
	int coin = rand() % 2;
	if (coin) {
		currentPlayer = playerOne;
		targetPlayer = playerTwo;
	}
	else {
		currentPlayer = playerTwo;
		targetPlayer = playerOne;
	}


See also
http://www.cplusplus.com/forum/beginner/266035/
Marking it "Solved" and then precisely NOT making a Game class isn't that impressive.

Yeah I know, I haven’t worked on the game class yet and just working on the ones I have now and making changes. Thanks though. :)
i also did what you just showed me and is still crashed my program.
Good to know - thanks for the update.

But if you want more than platitudes, you need to post fresh code.

Also, only posting part of a crashing program doesn't help much, if the real problem is in the code you didn't post.
never mind i fixed it. apparently i had to change the getline(cin,temp) to

getline(cin >> ws, temp);
choice = stoi(temp);

then it was fixed.
Topic archived. No new replies allowed.