Calculate interest using double type - C++ Data Type

C++ examples for Data Type:double

Description

Calculate interest using double type

Demo Code

#include <iostream> 
#include <cmath> 
using namespace std ; 

int main () { //from  w  ww.j  a v  a 2s . c o m
   // Interesting code starts 
   int principal ; 
   double interestRate ; 
   int numberOfYears ; 

   cout << " How much are you investing ?\n"; 
   cin >> principal ; 
   cout << " What 's the annual interest rate (%)?\ n"; 
   cin >> interestRate ; 
   cout << " How long for ( years )?\ n"; 
   cin >> numberOfYears ; 

   double finalBalance = pow (1.0 + interestRate * 0.01 , numberOfYears ) * principal ; 
   double interest = finalBalance - principal ; 

   cout << " You will earn "; 
   cout << interest ; 
   cout << "\n"; 
   return 0; 
} 

Result


Related Tutorials