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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
double Add(double a, double b);
double Sub(double a, double b);
double Mult(double a, double b);
double Div(double a, double b);
double Remain(double a, double b);
double Power(double a, double b);
double Add(double a, double b)
{
double answer = a + b;
return answer;
}
double Sub(double a, double b)
{
double answer = a - b;
return answer;
}
double Mult(double a, double b)
{
double answer = a * b;
return answer;
}
double Div(double a, double b)
{
double answer = a / b;
return answer;
}
double Remain(double a, double b)
{
double answer = fmod(a,b);
return answer;
}
double Power(double a, double b)
{
double answer = pow(a,b);
return answer;
}
int main ()
{
double num1,num2,answer;
int choice;
cout << "Please enter a number\n";
cin >> num1;
cout << "Please enter another number\n";
cin >> num2;
cout << "Select the function you would like to use" << endl;
cout << "1. Addition\n";
cout << "2. Subtraction\n";
cout << "3. Multiplication\n";
cout << "4. Division\n";
cout << "5. Remainder\n";
cout << "6. Power\n";
cin >> choice;
switch(choice)
{
case 1:
answer = Add(num1,num2);
break;
case 2:
answer = Sub(num1,num2);
break;
case 3:
answer = Mult(num1,num2);
break;
case 4:
answer = Div(num1,num2);
break;
case 5:
answer = Remain(num1,num2);
break;
case 6:
answer = Power(num1,num2);
break;
default:
cout << "Please select a valid function" << endl;
}
cout << "The answer is " << answer << "!";
}
| |