#include #include // this include file is needed for the output // manipulation - first cout statement you see below using namespace std; void main () { int x = 9, y = 2, z = 4, w; double a = 9.0, b = 2.0, c = 4.0, d; // the following line tells the computer to display numbers // in decimal (rather than scientific) notation, showing the // decimal point with 2 significant digits. // page 113 - 114 of your C++ text cout << fixed << showpoint << setprecision(2); w = x / y; // int/int into an int // the (i/i to i) means int/int stored in an int cout << " w is ( i/i to i) " << w << endl; d = a / b; // double/double into a double cout << " d is ( d/d to d) " << d << endl; d = x / y; // int/int into a double cout << " d is ( i/i to d) " << d << endl; w = a / y; // double/int into an int cout << " w is (d/i to i) " << w << endl; d = x / b; // int/double into a double cout << " d is (i/d to d)" << d << endl; w = a / b; // double/double into an int cout << " w is (d/d to i)" << w << endl; //explicit type casting - forcing a data type to another type d = (double)x / y; // this forces x to be transformed to a double // for this one calcuation cout << " d is (i typcast as double d/i to d)" << d << endl; d = x / (double)y; // this forces y to be transformed to a double // for this one calcuation cout << " d is (i typcast as double i/d to d)" << d << endl; d = (double)(x / y); // this forces the number x/y to be a double // for this one calcuation cout << " d is (typecast(int/int) as d)" << d << endl; }