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
|
#include <iostream>
#include <cstdlib>
using namespace std;
void CalRemain(int a, int b, int& c);
void DoubleCheck(int a, int b, int c);
int main()
{
int a; //num1
int b; //num2
int c; //remain
cout << "Enter two numbers, seperated by a space, you wish to divide."
<< endl
<< "Example: (3 15) will return 3/15= and its remainder if there is one!"
<< endl;
//take value of a and b
cin >> a >> b;
//Call this function
CalRemain(a, b, c);
cout << c << endl;
//Call this double check function
DoubleCheck(a, b, c);
cin.get();
cin.get();
return 0;
}
//Calculate the remainder of the 2
void CalRemain(int a, int b, int& c)
{
c = a - ((a/b)*b);
}
//Double check if the calculation was correct
void DoubleCheck(int a, int b, int c)
{
if (c == 0)
{
cout << a << " / " << b << " = " << ( a / b ) << endl;
cout << "No Remainder" << endl;
}
if (c != 0)
{
cout << a << " / " << b << " = " << ( a / b ) << endl;
cout << "Remainder= " << c << endl;
}
cout << endl;
cout << "Check my math with the equation below!!" << endl;
cout << endl;
cout << ( a / b ) << " * " << b << " + the remainder of " << c << "=" << ( a / b ) * b + c << endl;
cout << endl;
}
|