If else erroe

c

#1

When I run this code, I get the r,b,y chosen successfully. But when it’s time for the sub-colors, I’m stuck in the choices only. I can’t type another letter.



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

char color, ano;
int main(void)
{
    start:
    printf("\nChoose a color:\nr for red\nb for blue\ny for yellow\n");
    scanf("%c", &color);
    if (color=='r')
    {
        printf("You chose red. Now pick another:\nm for maroon\nv for vermillion\ns for scarlet"\n);
        scanf("%c", &color);

        if (color=='m')
        {
            printf("You chose maroon");
        }
        else if (color=='v')
        {
            printf("You chose vermillion");
        }
        else if (color=='s')
        {
            printf("You chose scarlet");
        }
        else
        {
            printf("Error100");
        }
    }
    else if (color=='b')
        {
        printf("You chose blue. Now pick another:\nc for cerulean\ni for indigo\na for azure");
        scanf("%c", &ano);

        if (ano=='c')
        {
            printf("You chose cerulean");
        }
        else if (ano=='i')
        {
            printf("You chose indigo");
        }
        else if (ano=='a')
        {
            printf("You chose azure");
        }
        else
        {
            printf("Error");
        }
    }
    else if (color=='y')
        {
        printf("You chose yellow. Now pick another:\nk for amber\ng for goldenrod\nl for lemon");
        scanf("%c", &ano);

        if (ano=='k')
        {
            printf("You chose amber");
        }
        else if (ano=='g')
        {
            printf("You chose goldenrod");
        }
        else if (ano=='l')
        {
            printf("You chose lemon");
        }
        else
        {
            printf("Error");
        }
    }
    else
    {
        printf("Error101");
        goto start;
    }
    return 0;
}




#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.