CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 5
5.
Write a program which accept principle, rate and time from user and print the simple interest.
Once again, I find myself coding for something I have no prior interest. (Pun intended)
All jokes aside, I was able to find the Simple Interest equation from the Finance Formulas website. According to my research, the equation to calculate simple interest is the following:
S = P(r)(t)
S = Simple Interest
P = Principal
r = rate
t = time
"The simple interest formula is used to calculate the interest accrued on a loan or savings account that has simple interest. The simple interest formula is fairly simple to compute and to remember as principal times rate times time. An example of a simple interest calculation would be a 3 year saving account at a 10% rate with an original balance of $1000. By inputting these variables into the formula, $1000 times 10% times 3 years would be $300.
Simple interest is money earned or paid that does not have compounding. Compounding is the effect of earning interest on the interest that was previously earned. As shown in the previous example, no amount was earned on the interest that was earned in prior years.
As with any financial formula, it is important that rate and time are appropriately measured in relation to one another. If the time is in months, then the rate would need to be the monthly rate and not the annual rate." --Finance Formulas
Let's put that to the test. Here is the code I have created. Admittedly, this did not go through as smoothly as I intended. Originally, the dollar amount was incorrect because the formula did not segregate the dollars and cents within the equation. In order to correct this, I had to divide everything by 100. Ultimately, here is the formula I have implemented:
S = (P * r * t)/100
Below is the output. I tested the code using the example dollar amounts provided by Finance Formulas.
Principal Balance: $1000.00
Rate: 10%
Time: 3 years
Of course, I also tested additional figures and compared it to other online calculators. Just to be sure. When it comes to money, we cannot chance any mistakes.
Principal Balance: $95.00
Rate: 2.5%
Time: 5 years
According to Calculator Soup, the interest is $11.88. (This was automatically rounded to the nearest dollar)
Next, I used WebMath to calculate the interest. Once again, it came to $11.88. (Automatically rounded)
Compared to my Simple Interest Calculator, which does not round to the nearest dollar, the interest is $11.875.
Once again, I find myself coding for something I have no prior interest. (Pun intended)
All jokes aside, I was able to find the Simple Interest equation from the Finance Formulas website. According to my research, the equation to calculate simple interest is the following:
S = P(r)(t)
S = Simple Interest
P = Principal
r = rate
t = time
"The simple interest formula is used to calculate the interest accrued on a loan or savings account that has simple interest. The simple interest formula is fairly simple to compute and to remember as principal times rate times time. An example of a simple interest calculation would be a 3 year saving account at a 10% rate with an original balance of $1000. By inputting these variables into the formula, $1000 times 10% times 3 years would be $300.
Simple interest is money earned or paid that does not have compounding. Compounding is the effect of earning interest on the interest that was previously earned. As shown in the previous example, no amount was earned on the interest that was earned in prior years.
As with any financial formula, it is important that rate and time are appropriately measured in relation to one another. If the time is in months, then the rate would need to be the monthly rate and not the annual rate." --Finance Formulas
Let's put that to the test. Here is the code I have created. Admittedly, this did not go through as smoothly as I intended. Originally, the dollar amount was incorrect because the formula did not segregate the dollars and cents within the equation. In order to correct this, I had to divide everything by 100. Ultimately, here is the formula I have implemented:
S = (P * r * t)/100
Below is the output. I tested the code using the example dollar amounts provided by Finance Formulas.
Principal Balance: $1000.00
Rate: 10%
Time: 3 years
Of course, I also tested additional figures and compared it to other online calculators. Just to be sure. When it comes to money, we cannot chance any mistakes.
Principal Balance: $95.00
Rate: 2.5%
Time: 5 years
According to Calculator Soup, the interest is $11.88. (This was automatically rounded to the nearest dollar)
Next, I used WebMath to calculate the interest. Once again, it came to $11.88. (Automatically rounded)
Compared to my Simple Interest Calculator, which does not round to the nearest dollar, the interest is $11.875.
Comments
Post a Comment