1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/*
Write a program that finds the amount in a savings account after a certain time has gone by.
Task 1 Ask the user for the original amount of money, the interest rate and the time.
Task 2 Calculate the amount of money you will have if the original amount of money, P, is earning interest at
r% for t years (compounded annually), the amount of money, A, will be:
A = P(1 + r/100)t
Task 3 The output should look like this:
After ____ years at interest rate ____%, $____ will become $_______.
*/
#include <cstdlib>
#include <iostream>
#include <cmath>
double getPrincipal();
double getRate();
double getYears();
double computeAmount(double principal, double rate, double years);
void displayAmount(double principal, double rate, double years, double amount);
using namespace std;
int main(int argc, char *argv[])
{
getPrincipal();
getRate();
getYears();
computeAmount();
displayAmount();
system("PAUSE");
return EXIT_SUCCESS;
}
double getPrincipal()
{
double principal;
cout << "what is the principal ammount?" << endl;
cin >> principal;
return principal;
}
double getRate()
{
double rate;
cout << "What is the percentage rate?" << endl;
cin >> rate;
return rate;
}
double getYears()
{
double years;
cout << "Over how many years will the money stay in the bank?" << endl;
cin >> years;
return years;
}
//function that computes the amount based on the principal, rate and years
double computeAmount(double principal, double rate, double years)
{
double computeAmount;
computeAmount = principal pow((1 + rate / 100),years);
cout << computeAmount << endl;
return computeAmount;
}
//function that displays the principal, rate , years, and amount
void displayAmount(double principal, double rate, double years, double amount)
{
double displayAmount;
cout << "After" << years << "years at interest rate" << rate << "%, $" << principal << "will become $" << computeAmount <<"." << endl;
}
|