vendredi 20 octobre 2017

If statement with multiple conditions, in c.

I am sorry if this has been posted before, could'nt find any topic closely related to this one. Anyways, the newbie that I am, I cannot seem to figure out why the code is outputting "\n%d is highest!" for all three cases. I've tried to add "break" after the printf operation at the conditions, no luck..

int main()
{
    int n1, n2, n3;
    printf("Input three integers, and let program find highest: ");
    scanf("%d %d %d", &n1, &n2, &n3);
    printf("chosen: %d %d %d", n1, n2, n3);

        if(n1>n2&&n1>n3);
    {
        printf("\n%d is highest!", n1);

    }

        if(n2>n1&&n2>n3);
    {
        printf("\n%d is highest!", n2);
    }

        if(n3>n2&&n3>n1);
    {
        printf("\n%d is highest!", n3);
    }
}

Aucun commentaire:

Enregistrer un commentaire