ID and ship

I found a problem with the prompt “ID and ship”, wherein you enter an alphabet(b,c,d,f) and give output of the ship’s class (Battleship, cruiser etc.). However, in the scanf function for taking the alphabet, I get weird answers using scanf("%c", &c) but right answer with scanf(" %c", &c). What could be the cause of getting it right with just a space?

The code:

int main(void) {
// your code goes here
//number of test cases
int n;
char c;
scanf("%d", &n);

//for each test case
while(n--){
    
}
        scanf("%c", &c);
        if(c == 'B' || c == 'b')
        printf("BattleShip\n");
        else if(c == 'C' || c == 'c')
        printf("Cruiser\n");
        else if (c == 'D' || c == 'd')
        printf("Destroyer\n");
        else
        printf("Frigate\n");
}
return 0;

}