'(Bug) Switch Statement on a turn based game
So im tryna make a turn based game and i got a bug on the switch() statement. Here's my code :
#include <iostream>
using namespace std;
int main()
{
int choice;
int enemyhp;
enemyhp = 10;
do
{
cout<<"Oh no there is an enemy!";
cout<<"Please enter 1 if you want to attack!\n";
cin>>choice;
switch(choice)
{
case 1:
if(enemyhp=10)
{
enemyhp-=3;
cout<<"Wack!\n";
cout<<"You wacked the enemy!\n";
break;
}
break;
default:
cout<<"Enemy : That won't stop me\n";
break;
}
}
while(1);
{
cout<<endl;
}
}
What i expect :
- The player typed 1.
- The program does case 1.
- And then the enemy says "That won't stop me". ================================================== What it does :
- The player typed 1.
- The program does case 1.
- It goes back to the cout<<"Oh no there is an enemy!".
- Not the cout<<""That won't stop me".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
