Categories
Pemprogramman C++ Uncategorized

contoh program switch case c++

Kali ini kami akan share contoh program sederhana switch c++, Semoga ini bermanfaar bagi teman-teman semua.

#include<iostream>
using namespace std;
main()
{
 long int q, price, total, pay,d;
 cout<<"**********FRESH**********" <<endl;
 cout<<"1. Juice" <<endl;
 cout<<"2. Soft Drink" <<endl;
 cout<<"3. Milk Shake" <<endl;
 cout<<"4. Tiramisu" <<endl;
 cout<<"5. Cookies Cream" <<endl;
 cout<<"--------------------------" <<endl;

 cout<<"Enter your choice [1/2/3/4/5]= ";
 cin>>price;
 cout<<"--------------------------" <<endl;

 switch (price)
 {
 case 1:
  cout<<"Fresh Menu= Juice" <<endl;

  cout<<"Price= Rp 10.000,-" <<endl;
  price= 10000;
 break;

 case 2:
  cout<<"Fresh Menu= Soft Drink" <<endl;
  cout<<"Price= Rp 10.000,-" <<endl;
  price= 15000;
 break;

 case 3:
  cout<<"Fresh Menu= Milk Shake" <<endl;
  cout<<"Price= Rp 10.000,-" <<endl;
  price= 20000;
 break;

 case 4:
  cout<<"Fresh Menu= Tiramisu" <<endl;
  cout<<"Price= Rp 10.000,-" <<endl;
  price= 18000;
 break;

 case 5:
  cout<<"Fresh Menu= Cookies Cream" <<endl;
  cout<<"Price= Rp 10.000,-" <<endl;
  price= 16000;
 break;
 }

 cout<<"Quantity= ";
 cin>>q;

 total= q*price;
 cout<<"Total= " <<total <<endl;

 
 if (q>=2)
 {
  d= 0.1*total;
  //cout<<"Discount= " <<d;
 }

 pay= total-d;
 cout<<"Pay= " <<pay <<endl;
 cout<<"--------------------------";
}

Leave a Reply

Your email address will not be published. Required fields are marked *