Reputation: 1
i am new to programming so the code i use is rather limited to what i've learned. at any rate im developing a scenario in which a user inputs one of two choices that will trigger different sets of code to execute or at least that is what im trying to do. however as i walk through my code it is executing it as if there were no if statements everything is running as one block. im pretty sure my logic is ok and that if anything my syntax is iffy. if there is anything you guys could do to help not just solve my issue if possible i'd like to learn rather than just have things fixed. thank you for your time.
int main()
{
int move = 0, pstrength = 10, pdefense = 20, pintelligence = 40, php = 10, estrength = 30,
edefense = 40, eintelligence = 25, ehp = 10;
printf("Battle Start!\n\nYour HP: %d Enemy HP: %d\n\n1 - Attack\n2 - Magic\n\n", php, ehp);
float pap = (float)pstrength / (float)edefense * 5;
float pmp = (float)pintelligence / (float)eintelligence * 5, eap = (float)estrength /
(float)pdefense * 5;
do {
printf("Select your move: ");
/player will chose what action to preform if action 1 is selected then player attacks if the enemy does not fall to 0 hp the enemy attacks then the loop resets and prompts for a second round of input/
scanf("%d", &move);
if (move = 1); {
printf("\nYou attacked the enemy!\n");
ehp = ehp - (float)pap;
if (ehp > 0){
printf("The enemy attacked you!\n\n");
php = php - (float)eap;
printf("Your HP: %dEnemy HP: %d\n\n", php, ehp);
}
}
if (move = 2); {
printf("\nYou shocked the enemy!\n");
ehp = ehp - pmp;
if (ehp > 0){
printf("The enemy attacked you!\n");
php = php - (float)eap;
printf("Your HP: %dEnemy HP: %d\n\n", php, ehp);
}}
} while (php >= 0 && ehp >= 0);
if (php <= 0)
printf("You Died!");
else
printf("You Won!");
return 0;
}
i ran a debug and whats happening is regardless of my selection if (move=1) or if (move=2) it runs systemically as in if i input 2 at the start it runs as if i input 1 and so on.
Upvotes: 0
Views: 644
Reputation: 98
You have semicolons after your if statement blocks! the correct syntax for if statements is if(condition) {code}
Upvotes: 0
Reputation: 3295
;
after each of your if
statements. Remove them. ==
not =
which is assignment.It will look like this :
if (move == 1) { ... }
Upvotes: 5