// Mr. Minich
// Computer Science Using C++
// Ch. 5 Demo Program #2
// January 30, 2000 
// Purpose - to illustrate promotion (implicit type conversion) and typecasting (explicit type conversion)

#include <iostream.h>

int main()
{
	int int1 = 1;       // int1 is declared and initialized in one statement 
    	int int2 = 2;                   
int int3; // int3 is not initialized
double double1; double double2 = 2.0; int3 = int1 + int2; // int3 = 3 (the whole number) cout << "int3 = " << int3 << endl; double1 = int1 + double2; // double1 = 3.0 (the decimal number) // this is an example of promotion, where C++ automatically // promotes int1 (the whole number) to the double type in order // to be able to perform the addition of two doubles. Technically, // C++ cannot add an int to a double even though both are 4-bytes.
cout << "double1 = " << double1 << endl; double2 = 1999.99; cout << "The price of the computer is $" << double2 << endl; cout << "The price of the computer is $" << int (double2) << endl;
// typecasting is used here by the programmer to // force C++ to interpret double2 as an integer // resulting in the truncation of the value 1999.99 to simply 1999 // Summary: Promotion is automatically used by the compiler // to evaluate expressions while typecasting is explicitly // used by the programmer for whatever reason. Typecasting and // promotion are examples of mixing data types. return 0; }// end of main