/* Filename: arithmetic.cpp Author: Br. David Carlson Br. Isidore Minerd Date: January 11, 2005 Modified: July 16, 2009 This program tests various arithmetic operations and rounding functions. Each test is explained in the screen output that precedes each answer. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET Microsoft Visual Studio 2008 g++ under Linux */ #include using namespace std; int main(void) { int IntNum, IntAnswer; float FloatAnswer; cout << "Test 1:" << endl; IntNum = 4; cout << "IntNum initially is " << IntNum << endl; IntAnswer = IntNum + 5; cout << "IntAnswer = IntNum + 5 puts into IntAnswer the value " << IntAnswer << endl; cout << endl << "Test 2:" << endl; IntAnswer++; cout << "After doing IntAnswer++, printing IntAnswer gives " << IntAnswer << endl; cout << endl << "Test 3:" << endl; IntAnswer = 50; cout << "We reset IntAnswer to value " << IntAnswer << endl; cout << "Putting IntAnswer++ inside an output statement gives " << IntAnswer++ << endl; cout << "Afterwards, the value of IntAnswer is " << IntAnswer << endl; cout << endl << "Test 4:" << endl; IntAnswer = 22; cout << "We reset IntAnswer to value " << IntAnswer << endl; cout << "Putting ++IntAnswer inside an output statement gives " << ++IntAnswer << endl; cout << "Afterwards, the value of IntAnswer is " << IntAnswer << endl; cout << endl << "Test 5:" << endl; IntNum = 4; cout << "We reset IntNum to value " << IntNum << endl; cout << "Printing 2 * IntNum - 3 gives " << 2 * IntNum - 3 << endl; cout << endl << "Test 6:" << endl; IntNum = 4; cout << "We reset IntNum to value " << IntNum << endl; cout << "Printing 2 * (IntNum - 3) gives " << 2 * (IntNum - 3) << endl; cout << endl << "Test 7:" << endl; IntAnswer = 15 / 4; cout << "IntAnswer = 15 / 4 puts into IntAnswer the value " << IntAnswer << endl; cout << endl << "Test 8:" << endl; FloatAnswer = 15 / 4; cout << "FloatAnswer = 15 / 4 puts into FloatAnswer the value " << FloatAnswer << endl; cout << endl << "Test 9:" << endl; FloatAnswer = 15.0 / 4.0; cout << "FloatAnswer = 15.0 / 4.0 puts into FloatAnswer the value " << FloatAnswer << endl; return 0; }