jeudi 14 novembre 2019

If/Else (Beginner)

int x = 0;

printf("Geben Sie bitte ihr Alter ein \n");
scanf_s("%i",&x);

if (x <= 15)
{
    printf("Sie duerfen keinen Alkohol trinken! \n");
}

else
{
    printf("Sie duerfen Bier trinken \n");

    if (x >= 18)
    {
        printf("Sie duerfen Alkohol jeglicher Art trinken! \n");
    }
}

(Between 0-15 -- no alcohol) (Between 16-17 --- beer is allowed) (Between 18+ ---- everything containing alcohol is allowed)

The Problem is that when you say that you're 18+ years old, then it shows the second part [ printf("Sie duerfen Bier trinken \n"); ] as well, and I really dont understand how to fix this.

I'm a beginner and I have nearly no experience, thanks for the help and sorry my English sucks..

Aucun commentaire:

Enregistrer un commentaire