/*
* This interactive C++ program demonstrates the arithmetic
* operators, along with the unary + and - operators.
*
* @creator gdt
* @created 02001.09.08
* @version 02016.08.24
*/
#include
#include
#include
using namespace std;
int main(int, char**) {
//freopen("x.out", "w", stdout);
cerr << "Enter two integers: ";
int a, b; //define two int variables named a b
cin >> a;
cin >> b;
cout << "Numbers entered: " << a << " and " << b << endl;
int sum = a + b;
cout << a << " + " << b << " is " << sum << endl;
int diff = a - b;
cout << a << " - " << b << " is " << a - b << endl;
int product = a * b;
cout << a << " * " << b << " is " << a * b << endl;
int quotient = a / b;
cout << a << " / " << b << " is " << quotient << endl;
int remainder = a % b; //modulus operator
cout << a << " % " << b << " is " << remainder << endl;
float real = a / b; //int divided by int results in integer division
cout << a << " / " << b << " is " << real << endl;
real = a / (float)b; //typecast b to be type float (this EXPR only)
cout << a << " / " << b << " is " << real << endl;
int result = a + b * a;
cout << a << " + " << b << " * " << a << " is " << result << endl;
result = (a + b) * a; //()'s used to alter operator precedence
cout << "(" << a << " + " << b << ") * " << a << " is "
<< result << endl;
sum = a + -b;
cout << a << " + " << -b << " is " << sum << endl;
a = -a;
sum = +a + b;
cout << a << " + " << b << " is " << sum << endl;
sum = product = diff = quotient = remainder = 0;
return EXIT_SUCCESS;
}
/***
Numbers entered: 5 and 8
5 + 8 is 13
5 - 8 is -3
5 * 8 is 40
5 / 8 is 0
5 % 8 is 5
5 / 8 is 0
5 / 8 is 0.625
5 + 8 * 5 is 45
(5 + 8) * 5 is 65
5 + -8 is -3
-5 + 8 is 3
Numbers entered: 8 and 5
8 + 5 is 13
8 - 5 is 3
8 * 5 is 40
8 / 5 is 1
8 % 5 is 3
8 / 5 is 1
8 / 5 is 1.6
8 + 5 * 8 is 48
(8 + 5) * 8 is 104
8 + -5 is 3
-8 + 5 is -3
Numbers entered: -3 and 5
-3 + 5 is 2
-3 - 5 is -8
-3 * 5 is -15
-3 / 5 is 0
-3 % 5 is -3
-3 / 5 is 0
-3 / 5 is -0.6
-3 + 5 * -3 is -18
(-3 + 5) * -3 is -6
-3 + -5 is -8
3 + 5 is 8
Numbers entered: 0 and -9
0 + -9 is -9
0 - -9 is 9
0 * -9 is 0
0 / -9 is 0
0 % -9 is 0
0 / -9 is 0
0 / -9 is -0
0 + -9 * 0 is 0
(0 + -9) * 0 is 0
0 + 9 is 9
0 + -9 is -9
***/