C++ examples for Data Type:double
Calculate interest using double type
#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; }