#include <cstdlib> |
#include <iostream> |
using namespace std; |
int main(int argc, char *argv[]) |
{ |
float a, b, hasil; |
int pilihan; |
cout<<"kalkulator sederhana\n"; |
cout<<"1. perkalian\n"; |
cout<<"2. pembagian\n"; |
cout<<"3. penjumlahan\n"; |
cout<<"4. pengurangan\n\n"; |
cout<<"masukkan pilihan : "; |
cin>>pilihan; |
switch (pilihan){ |
case 1 : cout<<"perkalian \n"; |
cout<<"\nmasukkan bilangan 1: "; |
cin>>a; |
cout<<"\nmasukkan bilangan 2: "; |
cin>>b; |
hasil=a*b; |
cout<<"\nhasil perkalian bilangan itu :"<<hasil<<"\n\n"; |
break; |
case 2 : cout<<"pembagian \n"; |
cout<<"\nmasukkan bilangan 1: "; |
cin>>a; |
cout<<"\nmasukkan bilangan 2: "; |
cin>>b; |
hasil=a/b; |
cout<<"\nhasil pembagian bilangan itu :"<<hasil<<"\n\n"; |
break; |
case 3 : cout<<"penjumlahan \n"; |
cout<<"\nmasukkan bilangan 1: "; |
cin>>a; |
cout<<"\nmasukkan bilangan 2: "; |
cin>>b; |
hasil=a+b; |
cout<<"\njumlah bilangan itu adalah :"<<hasil<<"\n\n"; |
break; |
case 4 : cout<<"pengurangan \n"; |
cout<<"\nmasukkan bilangan 1: "; |
cin>>a; |
cout<<"\nmasukkan bilangan 2: "; |
cin>>b; |
hasil=a-b; |
cout<<"\nhasil pengurangan bilangan itu adalah :"<<hasil<<"\n\n"; |
break; |
default: cout<<"diluar jangkauan"; |
} |
system("PAUSE"); |
return EXIT_SUCCESS; |
} |
Hasil compile
Tidak ada komentar:
Posting Komentar