C++ examples for Data Type:Cast
Calculate interest on a loan using type casting.
#include <stdio.h> int main()//from w w w. j a va 2s . com { int days=45; // Days since loan origination. float principle = 3500.00; // Original loan amount float interest_rate=0.155; // Annual interest rate float daily_interest; // Daily interest rate daily_interest=interest_rate/float(365); // Type cast days // to float. // Because days is integer, convert it to float also. daily_interest = principle * daily_interest * float(days); principle+=daily_interest;// Update principle with interest. printf("The balance you owe is %.2f", principle); return 0; }