#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <cstdlib>
//Program kalkulator sederhana
main(){
int pilihan;
double nilai1,nilai2,hasil;
awal:
cout<<"Ini merupakan program kalkulator sederhana"<<endl;
cout<<"1. Operasi Perkalian"<<endl;
cout<<"2. Operasi Penjumlahan"<<endl;
cout<<"3. Operasi Pengurangan"<<endl;
cout<<"Masukkan pilihan anda (1/2/3) : ";
cin>>pilihan;
system("cls");
switch(pilihan)
{
case 1: cout<<"Anda akan mengalikan bilangan (Y/N)"<<endl;
if(getch()=='y'){
cout<<"Nilai 1 : ";
cin>>nilai1;
cout<<"Nilai 2 : ";
cin>>nilai2;
cout<<"Hasil = "<<nilai1*nilai2;}
else{goto awal;}
break;
case 2: cout<<"Anda akan menjumlahkan bilangan (Y/N)"<<endl;
if(getch()=='y'){
cout<<"Nilai 1 : ";
cin>>nilai1;
cout<<"Nilai 2 : ";
cin>>nilai2;
cout<<"Hasil = "<<nilai1+nilai2;}
else{goto awal;}
break;
case 3: cout<<"Anda akan mengurangkan bilangan (Y/N)"<<endl;
if(getch()=='y'){
cout<<"Nilai 1 : ";
cin>>nilai1;
cout<<"Nilai 2 : ";
cin>>nilai2;
cout<<"Hasil = "<<nilai1-nilai2<<endl;}
else{goto awal;}
break;
default:
cout<<"Anda tidak memilih salah satu";
}
getch();
}
No comments:
Post a Comment