vendredi 9 août 2019

warning: statement with no effect [-Wunused-value] with if statements

so i was trying to figure out while loops and mostly if statements so i tried to make this little game where you have an amount of health and so does a monster, a loop runs as long as you both have more than 0 health,so each loop the monster would deal 50 damage to you, but using scanf and if statements the situation can be altered by inserting "2" you decrease the damage you take,by using "3" you add to your health and by using "1" you cause damage to the monster but for some reason the IF statements responsible for these events don't seem to be working

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(){
    int monsterhealth =100;
    int health =100;
    int damage =50;
    while(health>0&&monsterhealth>0){
        int action [10];
        printf("player has %d health \n",health);
        printf("monster has %d health\n",monsterhealth);
        printf("act:attack[1]\ndefend[2]\npotion[3]\n");
        scanf ("%d",action);
        if(action==1){(monsterhealth==monsterhealth-40);}
        else if(action==2){(damage==damage-30);}
        else (action==3);{(health==health+100);};
        health=health-damage;

    }
}

Aucun commentaire:

Enregistrer un commentaire