jeudi 20 août 2020

Problem with bool variables sharing the same values in an if else comparator

I am trying to make a game with 6 (counting the tutorial) missions in it. There are 6 bool variables, one for each mission. An if else comparator checks what variables are true, and sends you to the appropriate mission. The comparator works well enough if only 1 variable is true, but it if multiple variables are true than it does not. Here is a more simplified version of the code that presents the same error.

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

int main()
{
bool tutorial = true;
bool mission1 = true;
bool mission2 = true;

if (tutorial) {
    printf("It does not work");
}
else if (tutorial, mission1) {
    printf("It does work");
}
else {
    printf("It doesn't work");
}
}

What should happen is the program prints out "It does work". Instead, it prints out the "It doesn't work". While I am aware that if I only wanted the program to print the middle option, I would put

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

int main()
{
bool tutorial = true;
bool mission1 = true;
bool mission2 = true;

if (tutorial, mission1) {
    printf("It does not work");
}

}

That would prevent you from playing more than 1 mission as well. Please help.

Aucun commentaire:

Enregistrer un commentaire