හරි අපි බලමු කොහොමද C ++ භාවිතා කරලා සරල / මුලික (Basic) Calculator එකක් හදා ගන්නේ කියලා
මේ Calculator එක භාවිතා කරලා ඔයාලට Basic Arithmatic Operations වන
1) එකතු කිරීම
2) අඩුකිරීම
3) ගුණකිරීම
4) බෙදීම
කියන ගණනයන් කරගන්න පුළුවන් . ඒවගේම මේකට cmath library එක එකතු කරලා නිසා ඔයාලට පුළුවන් යම් සංඛ්යාවක බලයක් හොයන්නත්.
මේ cal එකේ source code පහලින් දාලා තියෙනවා.ඔයාලත් කැමතිනම් මේ source code, Codeblocks වගේ IDE එකක දාල run කරලා බලන්න
(මේක Basic calculator එකක් විතරයි )
#include<iostream>
#include<cmath>
using namespace std;
int main(){
double num1,num2;
int op;
cout<<"Enter the first number"<<endl;
cin>>num1;
cout<<"Enter the second number"<<endl;
cin>>num2;
cout<<"Enter the arithmetic operation"<<endl;
cout<<"1 Addition"<<endl;
cout<<"2 Subtraction"<<endl;
cout<<"3 Multiplication"<<endl;
cout<<"4 Division"<<endl;
cout<<"5 Power"<<endl;
cout<<"Enter the number"<<endl;
cin>>op;
cout<<" "<<endl;
switch(op){
case 1: cout<<(num1+num2)<<endl;
break;
case 2: cout<<(num1-num2)<<endl;
break;
case 3: cout<<(num1*num2)<<endl;
break;
case 4:{
if(num2==0)cout<<0<<endl;
else cout<<(num1/num2)<<endl;
}
break;
case 5:cout<<pow(num1,num2)<<endl;
break;
default :cout<<"Invalid operation"<<endl;
}
return 0;
}
Thank you!
මේ Calculator එක භාවිතා කරලා ඔයාලට Basic Arithmatic Operations වන
1) එකතු කිරීම
2) අඩුකිරීම
3) ගුණකිරීම
4) බෙදීම
කියන ගණනයන් කරගන්න පුළුවන් . ඒවගේම මේකට cmath library එක එකතු කරලා නිසා ඔයාලට පුළුවන් යම් සංඛ්යාවක බලයක් හොයන්නත්.
මේ cal එකේ source code පහලින් දාලා තියෙනවා.ඔයාලත් කැමතිනම් මේ source code, Codeblocks වගේ IDE එකක දාල run කරලා බලන්න
(මේක Basic calculator එකක් විතරයි )
#include<iostream>
#include<cmath>
using namespace std;
int main(){
double num1,num2;
int op;
cout<<"Enter the first number"<<endl;
cin>>num1;
cout<<"Enter the second number"<<endl;
cin>>num2;
cout<<"Enter the arithmetic operation"<<endl;
cout<<"1 Addition"<<endl;
cout<<"2 Subtraction"<<endl;
cout<<"3 Multiplication"<<endl;
cout<<"4 Division"<<endl;
cout<<"5 Power"<<endl;
cout<<"Enter the number"<<endl;
cin>>op;
cout<<" "<<endl;
switch(op){
case 1: cout<<(num1+num2)<<endl;
break;
case 2: cout<<(num1-num2)<<endl;
break;
case 3: cout<<(num1*num2)<<endl;
break;
case 4:{
if(num2==0)cout<<0<<endl;
else cout<<(num1/num2)<<endl;
}
break;
case 5:cout<<pow(num1,num2)<<endl;
break;
default :cout<<"Invalid operation"<<endl;
}
return 0;
}
Thank you!

