Compounding Annual Interest on Card Balance

I have only been using C++ for a couple of days now. While I have experience with programming languages for recreational purposes (game design, mostly), I am not familiar with this language.

Our instructor has asked us to create a program that performs the following:

-Enter a card limit amount
-Enter the amount of money spent
-Enter an interest amount
-Enter the number of years the interest is annually compounded
-Show the card balance after expenses and interest are factored
-If the card balance exceeds the limit, display a message with the amount overdrawn

My issue is that while I can get the interest for the first year, if I enter any amount higher than 1 for years compounded, I get diminishing returns. I know it is because the interest isn't a whole number, but I don't know how to fix it.

Please keep in mind my skills are very limited. Here's the code I have:


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
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   float card_balance, interest, yearscomp, card_limit, total_expenses, intamount;
   
   // "card_balance" is the remaining balance of the credit card
   // "interest" is the interest rate
   // "yearscomp" is the number of years the interest rate is compounded
   // "card_limit" is the credit limit of the card
   // "total_expenses" is how much of the credit limit has been used
   // "intamount" is the amount of interest compounded on the total expenses after a given amount of time (in years)
   
   cout << "Enter the credit card limit:\n";
   cin >> card_limit;
   
   cout << "Enter the total expenses amount:\n";
   cin >> total_expenses;
     
   cout << "Enter the interest rate as whole number:\n";
   cin >> interest;
   
   cout << "Enter how often, in years, the interest is compounded:\n";
   cin >> yearscomp;
   
   intamount = (total_expenses *pow(interest/100, yearscomp));

   card_balance = (card_limit - (total_expenses + intamount));
 
   cout << "Your remaining balance is ";
   cout << card_balance;
   cout << " on your credit card.\n";
   
   if (card_balance < 0)
   {
   cout << "Sorry, your balance has exceeded your credit limit by ";
   cout << (card_balance - total_expenses);
   }
      
   return 0;
   
}
Topic archived. No new replies allowed.