Program C++ (Switch Case Penjumlahan)

Program Penggunaan Switch Case Penjumlahan (C++)

#include <iostream.h>
#include <conio.h>
#include <process.h>
void main()
{
int pil;
float a, b, c;
char ulang;
ulang = 'Y';
for(; ulang =='Y' || ulang == 'y' ; )
{
cout<<"============================================"<<endl;
cout<<" MENU"<<endl;
cout<<"============================================"<<endl;
cout<<"1. PENJUMLAHAN "<<endl;
cout<<"2. PENGURANGAN "<<endl;
cout<<"3. PERKALIAN "<<endl;
cout<<"4. PEMBAGIAN "<<endl;
cout<<"============================================"<<endl;
cout<<"masukkan pilihan ? "; cin>>pil;
cout<<endl;

switch (pil)
{
case 1: { system("cls");
cout<<"1. PENJUMLAHAN"<<endl;
cout<<"==============================="<<endl;
cout<<"masukan nilai a:‚ "; cin>>a;
cout<<"masukan nilai b: "; cin>>b;
c=a+b;
cout<<"-------------------------------"<<endl;
cout<<"hasil penjumlahan dari "<<a<<"+"<<b<<"="<<c<<endl;
cout<<"==============================="<<endl;
break; }

case 2: { system("cls");
cout<<"2. PENGURANGAN"<<endl;
cout<<"==============================="<<endl;
cout<<"masukan nilai a:  "; cin>>a;
cout<<"masukan nilai b: "; cin>>b;
c=a-b;
cout<<"-------------------------------"<<endl;
cout<<"hasil penjumlahan dari "<<a<<"-"<<b<<"="<<c<<endl;
cout<<"==============================="<<endl;
break; }

case 3: { system("cls");
cout<<"3. PERKALIAN"<<endl;
cout<<"==============================="<<endl;
cout<<"masukan nilai a:‚ "; cin>>a;
cout<<"masukan nilai b: "; cin>>b;
c=a*b;
cout<<"-------------------------------"<<endl;
cout<<"Hasil penjumlahan dari "<<a<<"*"<<b<<"="<<c<<endl;
cout<<"==============================="<<endl;
break; }

case 4: { system("cls");
cout<<"4. PEMBAGIAN"<<endl;
cout<<"==============================="<<endl;
cout<<"masukan nilai a:  "; cin>>a;
cout<<"masukan nilai b: "; cin>>b;
c=a/b;
cout<<"-------------------------------"<<endl;
cout<<"Hasil penjumlahan dari "<<a<<"/"<<b<<"="<<c<<endl;
cout<<"==============================="<<endl;
break; }

default: cout<<"tidak ada pilihan"<<endl;
}
cout<<endl;
cout<<"apakah anda ingin‚ ulang <Y/N>?  "; cin>>ulang;
cout<<endl;
}
getch();
}