loop

Nov 5, 2014 at 6:16am
1
2
3
4
5
6
7
8
9
10
11
12
char selection = '0';
int player_hp = 100;
int enemy_hp = 100;
for ( ; player_hp <= 0 || enemy_hp <= 0 ; ) {
cout << "[1]Attack [2]Run" << endl;
selection = _getch();
switch ( selection ) {
case '1': enemy_hp -= 50; break;
case '2': cout << "Escaped!" << endl; Menu(); break;
default: battle(); break;
}
}



for loop will execute its statement until the condition is true. but ,why this isnt printing anything?
Last edited on Nov 5, 2014 at 6:21am
Nov 5, 2014 at 8:17am
for ( ; player_hp <= 0 || enemy_hp <= 0 ; )

Because your condition is never met...

Both player and enemy hp is 100, so it's never going to go in there.
Nov 5, 2014 at 9:17am
Use a do{}while. That's executed at least once.
Topic archived. No new replies allowed.