Calculate interest on a loan using type casting. - C++ Data Type

C++ examples for Data Type:Cast

Description

Calculate interest on a loan using type casting.

Demo Code

#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;
}

Result


Related Tutorials