Mengetahui Kategori nilai menggunaan IF & Case


#include <iostream.h>
#include <conio.h>
void main()
{
   int nilai,p;
   cout<<"Masukkan Parameter : ";cin>>nilai;
   if (nilai<=39 ){
         p = 5;
   }
   else if (nilai > 39 && nilai <= 55 ){
         p = 4;
   }
   else if (nilai > 55 && nilai <= 64 ){
         p = 3;
   }
   else if (nilai > 64 && nilai <= 79 ){
         p = 2;
   }
   else if (nilai > 79 && nilai <= 100 ){
         p= 1;
   }
   switch(p){
         case 1:
              cout<<" Nilai : A"<<endl;
         break;
         case 2:
              cout<<" Nilai : B"<<endl;
              break;
         case 3:
              cout<<" Nilai : C"<<endl;
              break;
      case 4:
              cout<<" Nilai : D"<<endl;
         break;
         case 5:
              cout<<" Nilai : E"<<endl;
         break;
         default:
              cout<<"Parameter Belum Ada."<<endl;
   }
getch();
}

0 komentar:

Posting Komentar

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan