Do what you want to

do,Dream what you want to dream, Go where you want to go, Be what you want to be, because you only have one life and one chance to do all the things you want to do...


Friday, December 21, 2012

multilevel selection (else if with switch case)


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

main()
{
      int answ,points;
      printf("enter char");
      scanf("%d",&answ);
     
      switch(answ)
     
      {
      case 'a' : points =4;
                   break;
      case 'b' : points =3;
                   break;
      case 'c' : points =2;
                   break;
      case 'd' : points =1;
                   break;
      case 'f' :
      case 'i' :
      case 'w' : points =0;
                   break;  
                 
      }
     
      if((answ >='a')&&(answ<='d'))
              printf("passed, points earned = %d",points);
      else
          printf("failed, no points earned");

      system("pause");
}

No comments:

Post a Comment