1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <cmath>
double mult(double a, double b){
double sum=a*b;
return sum;
}
double add(double a, double b){
double sum=a+b;
return sum;
}
double sub(double a, double b){
double sum=a-b;
return sum;
}
double root(double a, double b){
double sum=sqrt(a);
return sum;
}
double pow(double a, double b){
double sum=pow(a,b);
return sum;
}
double div(double a, double b) {
double sum=a/b;
return sum;
}
void main2(double a, double b){
char op;
double sum;
std::cout<<"A's value is "<<a<<".\n";
std::cout<<"Declare the operation!\n";
std::cin>>op;
std::cout<<"Enter the magnitude of the operation!\n";
std::cin>>b;
if (op=='+'){
std::cout<<"add\n";
add(a,b); }
if (op=='-') {
std::cout<<"sub\n";
sub(a,b); }
if (op=='*') {
std::cout<<"mult\n";
mult(a,b); }
if (op=='/') {
std::cout<<"div\n";
div(a,b); }
if (op=='^') {
std::cout<<"pow\n";
pow(a,b); }
if (op=='~') {
root(a,b); }
if (op=='!') {
std::cout<<"not yet!";
}
main2(a,0);
}
int main() {
double a;
std::cout<<"Welcome to Charlie's Amazing Calculator!\n\n";
std::cout<<"Here is a operation key!\nAddition,";
std::cout<<"+\nSubtraction, -\nMultiplication, *\nDivision, \nPower, ^\nSquare Root, ~\nFactoral, !\nTerminate, #\n\n";
std::cout<<"Enter the value of the first number!\n\n";
std::cin>>a;
main2(a,0);
}
| |