samedi 3 septembre 2016

if else inside switch case c language

  • Here im trying to do switch then if else in it. I dont know where i missed but this doesnt work.

Here's my code:

include<stdio.h>
include<conio.h>

int main()
{
clrscr();

int grade;

printf("Input Grade");
scanf("%d",&grade);

switch(grade<101)
{
case 1:
    if (grade>=95)
    printf("A+");
    else
    printf("Invalid");
    break;
case 2:
    if (grade>=85)
    printf("A");
    else
    printf("Invalid");
    break;
default:
    printf("Invalid");
}
getch();
}

So I don't know what's the matter. Only the first case work, when i enter a lower number than 95 'A' isn't the result. Please help me out.

Aucun commentaire:

Enregistrer un commentaire