#include<iostream>
int add(int a, int b) {
int sum;
sum=a+b;
return sum;
}
int sub(int a, int b) {
int sub;
sub=a-b;
return sub;
}
int mul(int a, int b) {
int mul;
mul=a*b;
return mul;
}
float div(float a, float b) {
float div;
if (b==0) {
return 0;
}
else {
div=a/b;
return div;
}
}
int main() {
int num1, num2;
char ope,cont;
std::cout<<"*******************************************************************************\n"
<<"*** ***\n"
<<"*** Calculator, by Shubham Chaudhary ***\n"
<<"*** ***\n"
<<"*******************************************************************************\n\n";
std::cout<<"Input the Calculation you want to make. Ex: (3+3), (4*5), (5-3), (6/2).\n\n"
<<"Input: ";
std::cin>>num1>>ope>>num2;
switch(ope) {
case '+' :
std::cout<<"\n"<<num1<<'+'<<num2<<'='<<add(num1, num2);
break;
case '-' :
std::cout<<"\n"<<num1<<'-'<<num2<<'='<<sub(num1, num2);
break;
case '*' :
std::cout<<"\n"<<num1<<'*'<<num2<<'='<<mul(num1, num2);
break;
case '/' :
if (div(num1, num2)==0) {
std::cout<<"0 as Divsor not Allowed!";
break;
}
else {
std::cout<<"\n"<<num1<<'/'<<num2<<'='<<div(num1, num2);
break;
}
default :
std::cout<<"Unknown/Invalid Operation! Try Again!";
break;
}
std::cout<<"\n\nDo you want to continue(y/n)?\n"
<<"Input: ";
std::cin>>cont;
if (cont=='y' || cont=='Y') {
std::cout<<"\n\n";
main();
}
else
return 0;
}
Can anyone tell me how good and efficient is this code??? I is my project for the term and I want to confirm I can get a good grade!