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
|
#include <iostream>
#include <cmath>
using namespace std;
//functin prototypes
void getData(float & num1, float & num2);
void doTheMath(float num1, float num2, float & sumAdd, float & sumSub, float & multRes, float & divRes);
void displayResults(float num1, float num2, float & sumAdd, float & sumSub, float & multRes, float & divRes);
//==== main ==================================================================
//
//============================================================================
int main ()
{
float num1=0;
float num2=0;
float sumAdd=0;
float sumSub=0;
float multRes=0;
float divRes=0;
getData(num1, num2);
sumAdd=doTheMath(num1, num2, sumAdd, sumSub, multRes, divRes);
sumSub=doTheMath(num1, num2, sumAdd, sumSub, multRes, divRes);
multRes=doTheMath(num1, num2, sumAdd, sumSub, multRes, divRes);
divRes=doTheMath(num1, num2, sumAdd, sumSub, multRes, divRes);
displayResults(num1, num2, sumAdd, sumSub, multRes, divRes);
return 0;
} // end of "main"
//============================================================================
//==== getData ===============================================================
//
//============================================================================
void getData(float & num1, float & num2)
{
cout<<"Please enter two integer values: /n";
cin>>num1;
cin>>num2;
} // end of "getData"
//=============================================================================
//==== doTheMath ==============================================================
//
//=============================================================================
void doTheMath(float num1, float num2, float & sumAdd, float & sumSub, float & multRes, float & divRes)
{
sumAdd=num1+num2;
sumSub=num1-num2;
multRes=num1*num2;
divRes=num1/num2;
} // end of "doTheMath"
//=============================================================================
//==== displayResults =========================================================
//
//=============================================================================
void displayResults(float num1, float num2, float & sumAdd, float & sumSub, float & multRes, float & divRes)
{
if (num2==0){
cout<<"The sum of "<<num1<<" and "<<num2<<" is "<<sumAdd<<".\n";
cout<<"The difference, ("<<num1<<" - "<<num2<<") is "<<sumSub<<".\n";
cout<<"The product of "<<num1<<" and "<<num2<<" is "<<multRes<<".\n";
cout<<"Cannot divide an integer by zero.";
cout<<endl;}
else{
cout<<"The sum of "<<num1<<" and "<<num2<<" is "<<sumAdd<<".\n";
cout<<"The difference, ("<<num1<<" - "<<num2<<") is "<<sumSub<<".\n";
cout<<"The product of "<<num1<<" and "<<num2<<" is "<<multRes<<".\n";
cout<<num1<<" divided by "<<num2<<" is "<<divRes<<".\n";
cout<<endl;
}
} // end of "displayResults"
//========================================================================
|