> p1hp -= attack;
This isn't the value you calculated.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Hey Black Magic i have solved your problem.
Well just examine That you have typed this code in
p1hp -= p2attack;
Line 54. Which probarbly doesnt get executed because there are break; statements above it.
So You actually need to paste the code in between Line 46 and line 47 so that the value gets changed.
So here is the total program with the adjustment.
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int p1attack, p2attack, p1hp, p2hp;
char attack;
p1hp = 99;
p2hp = 99;
system("TITLE Game.");
while(p1hp > 0 && p2hp > 0)
{
cout << "Player 1 (HP:" << p1hp << ") Press 'A' to attack : ";
cin >> attack;
switch(attack)
{
case 'a':
case 'A':
srand ( time(NULL) );
p1attack = rand() % 99 + 1;
cout << "You hit " << p1attack << "!";
break;
default:
cout << endl << "INVALID SELECTION!";
break;
}
p2hp -= p1attack;
cout << endl << endl << "Player 2 (HP:" << p2hp << ") Press 'A' to attack : ";
cin >> attack;
switch(attack)
{
case 'a':
case 'A':
srand ( time(NULL) );
p2attack = rand() % 99 + 1;
p1hp -= p2attack;
cout << "You hit " << p2attack << "!" << endl;
break;
default:
cout << endl << "INVALID SELECTION!";
break;
}
}
getch();
}
Sky Diploma
Practically a Posting Shark
864 posts since Mar 2008
Reputation Points: 673
Solved Threads: 130
I actually put the code in 47 Keeping in mind that there is an option for an attacker not to attack also. right
For example if the user enters something other than "A".
Sky Diploma
Practically a Posting Shark
864 posts since Mar 2008
Reputation Points: 673
Solved Threads: 130
Yes . That is also a good solution ;) Cool Gamer 48
I dint think of that.
Sky Diploma
Practically a Posting Shark
864 posts since Mar 2008
Reputation Points: 673
Solved Threads: 130
Hey Black Magic i think you will need to end the game once a person's hp goes into negatives .So try using the || Operator instead of && in Line 16
Sky Diploma
Practically a Posting Shark
864 posts since Mar 2008
Reputation Points: 673
Solved Threads: 130