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 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
using namespace std;
double calculateAddition(double&num1,double&num2,double&output);
double calculateSubtraction(double&num1,double&num2,double&output);
double calculateProduct(double&num1,double&num2,double&output);
double calculateDivision(double&num1,double&num2,double&output);
double printOutput(double &output);
double getCode(double &num1, double &num2, double &codeee);
double printOutput(double &output);
void getData(double &num1, double &num2);
void endProgram(double &num1, double &num2);
int main()
{
//Declaring my variables
double output, num1, num2, codeee;
int code;
//Function call
getData(num1,num2);
code = getCode(num1,num2,codeee);
//If user enters two zeros, the program will end
if ((num1==0) && (num2==0))
{
int end=0;
endProgram(num1, num2);
}
else getData(num1, num2);
printOutput(output);
}
//Determines the calculation
void getData(double &num1, double &num2)
{
double codeee;
cout<<"Please enter a number"<<endl;
cin>>num1;
cout<<"Please enter another number"<<endl;
cin>>num2;
getCode(num1, num2, codeee);
return;
}
double getCode(double &num1, double &num2, double&codeee)
{
int code;
double output;
cout<<"Please enter the code"<<endl;
cin>>codeee;
if (code == 1)
{
calculateAddition(num1,num2,output);
}
else if (code == 2)
{
calculateProduct(num1,num2,output);
}
else if (code == 3)
{
calculateDivision(num1,num2,output);
}
else if (code == 4)
{
calculateSubtraction(num1,num2,output);
}
return codeee;
}
//Each calculation's function
double calculateAddition(double&num1,double&num2,double&output)
{
output=num1+num2;
cout << "The first number is." << " " << num1 << " " << "The second number is." << " " << num2 << " " << "The sum of these numbers is." << " " << output << endl;
return output;
}
double calculateSubtraction(double&num1,double&num2,double&output)
{
output=num1-num2;
cout << "The first number is." << " " << num1 << " " << "The second number is." << " " << num2 << " " << "The difference of these numbers is." << " " << output << endl;
return output;
}
double calculateProduct(double&num1,double&num2,double&output)
{
output= num1 * num2;
cout << "The first number is." << " " << num1 << " " << "The second number is." << " " << num2 << " " << "The product of these numbers is." << " " << output << endl;
return output;
}
double calculateDivision(double&num1,double&num2,double&output)
{
output=num1/num2;
cout << "The first number is." << " " << num1 << " " << "The second number is." << " " << num2 << " " << "The quotient of these numbers is." << " " << output << endl;
return output;
}
double printOutput(double &output)
{
cout<<"Your output is: "<<output<<endl;
return output;
}
void endProgram (double &num1, double &num2)
{
cout<<"Goodbye!"<<endl;
return;
}
|