Making Simply Calculator using C++
Calculator is one of many tools that we used in everdat. It’s very interesting when you can made it with yourself. So, do you interest to try it. let’s follow some tutorial in this article. Owh, i forgot to tell you that i used the Dev C++ Ver.5.11 for GUI (Graphic User Interface). Actually to Code and Compile the Script.
And that’s the script :
/*===============================================================
name program : simple program calculator;
created by Sufyan97
date : Agust 23 2016
===============================================================*/
#include <iostream>
using namespace std;
float perkalian (float angka1, float angka2){
return(angka1*angka2);
}
float pembagian (float angka1, float angka2){
return(angka1/angka2);
}
float penjumlahan (float angka1, float angka2){
return(angka1+angka2);
}
float pengurangan (float angka1, float angka2){
return(angka1-angka2);
}
void inputAngka(float& angka1,float& angka2){
cout<<"Masukan angka 1 : ";cin>>angka1;
cout<<"Masukan angka 2 : ";cin>>angka2;
}
void menu (int pilihan){
int pilih;
float angka1,angka2;
do{
system("CLS");
cout<<"=====Kalkulator Sederhana====="<<endl;
cout<<"1. Penjumlahan"<<endl;
cout<<"2. Pengurangan"<<endl;
cout<<"3. Perkalian"<<endl;
cout<<"4. Pembagian"<<endl;
cout<<"5. Exit"<<endl;
cout<<"=====Kalkulator Sederhana====="<<endl;
cout<<"Pilih menu : ";cin>>pilih;
while(pilih>5||pilih<0){
cout<<"Pilih menu (1-5): ";cin>>pilih;
}
switch(pilih){
case 1 :
cout<<"\n========Penjumlahan======\n";
inputAngka(angka1,angka2);
cout<<angka1<<" + "<<angka2<<" = "<<penjumlahan(angka1,angka2)<<endl;
system("Pause");
break;
case 2 :
cout<<"\n========Pengurangan======\n";
inputAngka(angka1,angka2);
cout<<angka1<<" - "<<angka2<<" = "<<pengurangan(angka1,angka2)<<endl;
system("Pause");
break;
case 3 :
cout<<"\n========Perkalian======\n";
inputAngka(angka1,angka2);
cout<<angka1<<" * "<<angka2<<" = "<<perkalian(angka1,angka2)<<endl;
system("Pause");
break;
case 4 :
cout<<"\n========Pembagian======\n";
inputAngka(angka1,angka2);
cout<<angka1<<"/"<<angka2<<" = "<<pembagian(angka1,angka2)<<endl;
system("Pause");
break;
}
}while(pilih!=5);
}
main(){
int pilihan;
cout<<"Selamat Datang diprogram Kalkulator Sederhana"<<endl;
cout<<"Ketik 1 untuk melanjutkan :";cin>>pilihan;
if(pilihan==1){
menu(pilihan);
}
else{
return(0);
}
}
|
- First of all, copy this script to Dev C++ work area. Actually i hope that you read the script and learn it :D
- Next, you compiled and run the script. With pressed the “f11” in your keyboard. And enjoy it
- When you Successed Compile and Run the program, this will appear.
- And the Menu’s.
- And this one Example.
So, this my shared and hope will hopefull to all of you. If you have some question in this Article you can Comment or PM me in Social Media or Email Me :D. Thanks
Leave a Comment