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
|
#include <iostream>
using namespace std;
void CalcIntResults(int nFirst, int nSecond, int &nAdd, int &nSubtract, int &nMultiply, int &nDivide);
int main(void)
{
int nFirst = 0;
int nSecond = 0;
int nResult = 0;
int nAdd = 0;
int nSubtract = 0;
int nMultiply = 0;
int nDivide = 0;
cout << "Please enter two integer values: " << endl;
cin >> nFirst >> nSecond;
cout << "Here are the results: " << endl;
CalcIntResults(nFirst, nSecond, nAdd, nSubtract, nMultiply, nDivide);
cout << nFirst << " plus " << nSecond << " equals " << nAdd << endl;
CalcIntResults(nFirst, nSecond, nAdd, nSubtract, nMultiply, nDivide);
cout << nFirst << " minus " << nSecond << " equals " << nSubtract << endl;
CalcIntResults(nFirst, nSecond, nAdd, nSubtract, nMultiply, nDivide);
cout << nFirst << " multiplied by " << nSecond << " equals " << nMultiply << endl;
if (nSecond == 0)
{
cout << nFirst << " divided by 0 equals 0" << endl;
}
else if (nSecond > 0)
{
CalcIntResults(nFirst, nSecond, nAdd, nSubtract, nMultiply, nDivide);
cout << nFirst << " divided by " << nSecond << " equals " << nDivide << endl;
}
}
void CalcIntResults(int nFirst, int nSecond, int &nAdd, int &nSubtract, int &nMultiply, int &nDivide)
{
nAdd = nFirst + nSecond;
nSubtract = nFirst - nSecond;
nMultiply = nFirst * nSecond;
nDivide = nFirst / nSecond;
}
|