-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.cpp
More file actions
30 lines (25 loc) · 980 Bytes
/
13.cpp
File metadata and controls
30 lines (25 loc) · 980 Bytes
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
// C++ program to input principal amount, rate of interest, and time period, and calculate the compound interest
// using while statement.
#include <iostream>
using std::cin, std::cout;
int main()
{
// declaring the required variables.
int time, year;
float principalAmount, netAmount, rateOfInterest, compoundInterest;
// entering the values for the variables from the console.
cout << "Enter the principal amount, rate of interest, and time: ";
cin >> principalAmount >> rateOfInterest >> time;
// calculating the compound interest.
netAmount = principalAmount;
year = 1;
while(year <= time)
{
netAmount *= 1 + rateOfInterest/100;
++year;
}
compoundInterest = netAmount - principalAmount;
// printing the calculated compound interest and net. amount to the console.
cout << "Compound interest: " << compoundInterest << "\n";
cout << "Net. amount: " << netAmount;
}