Creating a Calculator
Below I will give C ++ coding how to make a calculator. in a coding there are 3 stages to be done that is input, process, and output. here I create a procedure that is with the name of the calculator and make a code input of numbers by way inputted freely. just go to the tutorial.
Code
#include <iostream.h>
#include <conio.h>
void kalkulator();
void kalkulator(){
double angka;
double angka2;
double hasil;
char op;
char jawab;
cout<<"\n===============================================================";
cout<<"\n KALKULATOR SEDERHANA ";
cout<<"\n===============================================================";
cout<<endl;
cout<<" -- Operator --\n\n";
cout<<" '*' = Perkalian \n";
cout<<" '/' = Pembagian \n";
cout<<" '+' = Penjumlahan \n";
cout<<" '-' = Pengurangan \n";
cout<<"===============================================================\n";
cout<<" Masukkan Angka : ";
cin>>angka;
do{
if (angka == 0)
{
cout<<" Masukkan Angka : ";
cin>>angka;
}
cout<<" Operator : ";
cin>>op;
switch(op)
{
case 'c' : angka=0;
break;
case '+' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil= angka+angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
case '-' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil=angka-angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
case '*' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil=angka*angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
case '/' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil=angka/angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
}
cout<<"\n Apakah Perhitungan Mau Dilanjutkan?(Y/T) : ";
cin>>jawab;
cout<<endl;
}
while(jawab=='Y'||jawab=='y');
}
void main(){
cout<<"\n Nama : Muhammad Wahyu Imamuddin";
cout<<"\n NIM : 5160411049";
cout<<"\n Prodi: Teknik Informatika";
cout<<endl;
kalkulator();
getch();
}
Output
Well that is the code for making a calculator of some numbers are input freely. hopefully you understand with the codes C + + is very simple and can develop it so be a reliable progremmer. hopefully this tutorial provides benefits for those of you who again learn C ++ programming. If anything is wrong in my writing, I apologize profusely. Thank you for following my tutorials.
Code
#include <iostream.h>
#include <conio.h>
void kalkulator();
void kalkulator(){
double angka;
double angka2;
double hasil;
char op;
char jawab;
cout<<"\n===============================================================";
cout<<"\n KALKULATOR SEDERHANA ";
cout<<"\n===============================================================";
cout<<endl;
cout<<" -- Operator --\n\n";
cout<<" '*' = Perkalian \n";
cout<<" '/' = Pembagian \n";
cout<<" '+' = Penjumlahan \n";
cout<<" '-' = Pengurangan \n";
cout<<"===============================================================\n";
cout<<" Masukkan Angka : ";
cin>>angka;
do{
if (angka == 0)
{
cout<<" Masukkan Angka : ";
cin>>angka;
}
cout<<" Operator : ";
cin>>op;
switch(op)
{
case 'c' : angka=0;
break;
case '+' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil= angka+angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
case '-' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil=angka-angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
case '*' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil=angka*angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
case '/' : cout<<" Masukkan Angka : ";
cin>>angka2;
hasil=angka/angka2;
cout<<"==============================================================="<<endl;
cout<<" Hasil : "<<hasil<<endl;
angka=hasil;
break;
}
cout<<"\n Apakah Perhitungan Mau Dilanjutkan?(Y/T) : ";
cin>>jawab;
cout<<endl;
}
while(jawab=='Y'||jawab=='y');
}
void main(){
cout<<"\n Nama : Muhammad Wahyu Imamuddin";
cout<<"\n NIM : 5160411049";
cout<<"\n Prodi: Teknik Informatika";
cout<<endl;
kalkulator();
getch();
}
Output
Well that is the code for making a calculator of some numbers are input freely. hopefully you understand with the codes C + + is very simple and can develop it so be a reliable progremmer. hopefully this tutorial provides benefits for those of you who again learn C ++ programming. If anything is wrong in my writing, I apologize profusely. Thank you for following my tutorials.

Komentar
Posting Komentar