Sabtu, 29 Oktober 2011

Simple Calculator (.cpp)

Listing

#include <iostream.h>
#include <conio.h>

main ()
{
       int pilihan;
       double nilai1,nilai2,hasil;
      
       cout<<"\n"<<endl;
       cout<<"                    ----------KALKULATOR SEDERHANA--------"<<endl;
       cout<<"                    -                                    -"<<endl;
       cout<<"                    -        1.Operasi Penjumlahan       -"<<endl;
       cout<<"                    -        2.Operasi Pengurangan       -"<<endl;
       cout<<"                    -        3.Operasi Perkalian         -"<<endl;
       cout<<"                    -        4.Operasi Pembagian         -"<<endl;
       cout<<"                    -                                    -"<<endl;
       cout<<"                    --------------------------------------\n"<<endl;
       cout<<"Masukkan Pilihan Anda (1/2/3/4): ";
       cin>>pilihan;
      
       switch(pilihan)
{

       case 1:
            cout<<"\nAnda Akan Menjumlahkan Bilangan\n";
            cout<<"masukkan nilai 1   : ";
            cin>>nilai1;
            cout<<"masukkan nilai 2   : ";
            cin>>nilai2;
            hasil = nilai1 + nilai2;
            cout<<"_______________________+\n";
            cout<<"                     "<< hasil;
       break;
      
       case 2:
            cout<<"\nAnda Akan Mengurangkan Bilangan\n";
            cout<<"masukkan nilai 1    : ";
            cin>>nilai1;
            cout<<"masukkan nilai 2    : ";
            cin>>nilai2;
            hasil = nilai1 - nilai2;
            cout<<"_______________________-\n";
            cout<<"                      "<< hasil;
       break;
      
       case 3:
            cout<<"\nAnda Akan Mengalikan Bilangan\n";
            cout<<"masukkan nilai 1    : ";
            cin>>nilai1;
            cout<<"masukkan nilai 2    : ";
            cin>>nilai2;
            hasil = nilai1 * nilai2;
            cout<<"_______________________x\n";
            cout<<"                      "<< hasil;
       break;
      
       case 4:    
            cout<<"\nAnda Akan Membagi Bilangan\n";
            cout<<"masukan nilai 1    : ";
            cin>>nilai1;
            cout<<"masukkan nilai 2   : ";
            cin>>nilai2;
            hasil = nilai1 / nilai2;
            cout<<"_______________________:\n";
            cout<<"                     "<< hasil;
       break;
      
       default :
       cout<<"PILIHAN TIDAK SESUAI !!";
}

getch();
}
Pejumlahan


Pengurangan

Perkalian

Pembagian

Tidak ada komentar:

Poskan Komentar