jeudi 6 août 2020

Problems with bool variables within a if else comparator

I am trying to make an upgrade system within my game. I am using 3 bool variables (for 3 different weapons). I am having trouble making an if else comparator that will look at which bool variables are true/false (which weapons you have and don't have), and take you to an appropriate combat scenario. The if else comparator does not work, regardless of what weapon you have. It automatically goes to the "else" part of the statement (where you go if you do not have a weapon). I have included a simplified version, with only 1 bool variable. Please help.

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

int main()
{
    int choice;
    int choice2;
    bool weapon1 = false;
    
    start:
    printf("Where would you like to go? 1. Store  2. Arena: ");
    scanf("%d", &choice);
    if (choice == 1) {
        printf("You got weapon1 from the store \n");
        bool weapon1 = true;
        goto start;
    }
    else if (choice == 2) {
        printf("You went to the arena\n");
        if (weapon1) {
            printf("You won the battle because you had a weapon\n");
            exit(0);
        }
        else {
            printf("You lost the battle because you did not have a weapon\n");
            exit(0);
        }
    }
    

    return 0;
}


Aucun commentaire:

Enregistrer un commentaire