-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiomanip.cpp
51 lines (36 loc) · 1.22 KB
/
iomanip.cpp
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
// Programming challenge #16, this program calculates the interest earned
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Declaring variables
float INTEREST_RATE;
unsigned short int TIME;
float PRINCIPAL;
float INTEREST;
float AMOUNT;
// Get the principal balance
cout << "What is the principal balance? ";
cin >> PRINCIPAL;
// Get the interest rate
cout << "What is the interest rate? ";
cin >> INTEREST_RATE;
// Get the number of time the interest is compounded
cout << "How many times is the interest compounded? ";
cin >> TIME;
cout << "--------------------------------------------------------------------------------\n";
// Calculate the amount
AMOUNT = PRINCIPAL * powf(1+(INTEREST_RATE/(100*TIME)),TIME);
// Calculate the interest
INTEREST = AMOUNT - PRINCIPAL;
// Set precision
cout << fixed << setprecision(2);
// Display
cout << " Interest Rate " << setw(32) << INTEREST_RATE << "%" << endl;
cout << " Time Compounded " << setw(30) << TIME << endl;
cout << " Principal " << setw(29) << "$ " << PRINCIPAL << endl;
cout << " Interest: " << setw(31) << "$ " << INTEREST << endl;
cout << " Amount in savings " << setw(21) << "$ " << AMOUNT << endl;
return 0;
}