Casting Data Types Example

/*This program will demonstrate how to input a number at the keyboard
and it will cast the number into a different data type.*/
#include <iostream.h>//Header file for cin and cout
main()
{
	int num1, num2; //Declaring integer variables
	float f1, f2; // Declaring float variables

	cout << "please enter a number : ";
	cin >> num1;
	cout << num1 << "**\n";
	cout << float(num1) << "##\n";
	num2 = num1 + 3.2;
	cout <<"num2 = "<< num2 <<'\n';
	f2 = num1 + 3.2;
	cout << "f2 = " << f2 << '\n';
	cout <<"integer division "<< 5 / num1 << '\n';
	//An integer is casted into a float in the next line.
	cout <<"real division " << 5 / float(num1) << '\n';
	f1 = 3.2;
	cout << "f1 = " << f1 << '\n';
	cout << "f1 casted = " << int(f1) << '\n';
	return 0;
}

/*
Output of program

please enter a number : 2
2**
2##
num2 = 5
f2 = 5.2
integer division 2
real division 2.5
f1 = 3.2
f1 casted = 3
*/