Contoh Program case C++

Contoh Program Case
  //
  // Demonstrates switch statement

  #include <iostream.h>

  int main()
  {
    unsigned short int number;
 cout << "masukan hari 1-7: ";
    cin >> number;
    switch (number)
    {

case 0:   cout << "gak ada hari ke 0 sob!!";
break;
case 1:  cout << "hari senin\n";
break;
case 2:  cout << "hari selasa\n";
break;
case 3:  cout << "hari rabu\n";
break;
case 4:  cout << "hari kamis\n";
break;
case 5:  cout << "hari jumat\n";
break;
case 6:  cout << "hari sabtu\n";
break;
case 7:  cout << "hari Minggu\n";
break;
default: cout << "Aduh kegedean\n";
                break;
    }
   cout << "\n\n";
     return 0;
 }

----------------------------------------------------------------------
contoh 2
---------------------------------------------------------------------
#include <iostream.h>

int main()
{
unsigned short int number;
cout<< "masukan angka 1-10:";
cin>>number ;
switch(number)
{
case 0: cout<<"ups!!";
break;

case 1 : cout <<"ganjil\n";
break;
case 2 : cout <<"genap\n";
break;
case 3 : cout <<"ganjil\n";
break;
case 4 : cout <<"genap\n";
break;
case 5 : cout <<"ganjil\n";
break;
case 6 : cout <<"genap\n";
break;
case 7 : cout <<"ganjil\n";
break;
case 8 : cout <<"genap\n";
break;
case 9 : cout <<"ganjil\n";
break;
case 10 : cout <<"genap\n";
break;
}
cout<<"\n\n";
return 0;
}

0 komentar:

Post a Comment

Copyright © 2014 Dunia Naeta All Right Reserved