1 2
|
cin >> C1;
if (C1 = 1)
|
Why? Why do you need the user to enter 1, 2 and 3 for no real particular reason to attack, or enter battle? Anyway.. if you REALLY need them, what happens if the user enters something like "cows" for C1? The program will go haywire so you'll need to make sure the input is valid (see:
http://www.cplusplus.com/forum/articles/6046/).
Also.. look at your own code:
if (C1 = 1)
=
means to assign a value to something
==
means to compare a value to something else
That means you should've used
==
instead since you aren't comparing C1, C2 or C3 to anything - you are just assigning a value to them.
Also for your code:
if(Attack > Defense)
if(Defence > Attack)
What would happen if
Attack == Defence
?
I also recommend the ending bracers for a code block is on the same line as the starting bracers to make it neater and a tad easier to read.
1 2 3 4 5 6
|
if(Attack > Defense)
{
cout << "you strike the goblin!" << endl;
Damage = rand() % 5 + 1;
cout << "The goblin has this much health left " << Enemyhealth - Damage <<endl;
} //move this up to the line where the first braces is
|
To answer your first question -
I think you can use a boolean to check if the goblin is dead or not. So something like -
1 2
|
boolean goblin_isDead = false;
//..... etc
|
Then inside a loop in the goblin combat -
1 2 3 4
|
while (goblin_isDead == false)
{
//.....
}
|
Then later -
1 2 3 4
|
if (EnemyHealth == 0)
{
goblin_isDead = true; //assigns goblin_isDead true so that it'll break out of the loop
}
|
EDIT: In fact, you don't need a boolean. You can just do something like -
1 2 3 4
|
while (EnemyHealth > 0) //while the enemy still has more than 0 health
{
//... attack... defend.. etc
}
|