Programming project help?

This is a discussion on Programming project help? within the C++ Programming forums, part of the General Programming Boards category; Hello, I am really confused as to how to start my project that I was given for my C++ course. ...

1. Programming project help?

Hello, I am really confused as to how to start my project that I was given for my C++ course.

The instructions are:

Write a function declaration for a function that computes interest on a credit card account balance. The function takes arguments for the initial balance, the monthly interest rate, and the number of months for which interest must be paid. The value returned is the interest due. Do not forgetto compound the interest- that is, to charge interest on the interest due. This interest due is added into the balance due, and the interest for the next month is computed using this larger balance. Use a while loop. Embed the function in a program that reads the values for the interest rate, initial account balance, and number of months, then outputs ths interest due. Embed your function definition in a program that lets thge user compute the interest due on the credit account balance. The program should allow the user to repeat the calculation until the user said he or she wants to end the program.

The information that I am given through my instructor is:

Read the description carefully, insure that you allow the user a choice to run the program or exit.

The function prototype is:

double interest (double initBalance, double rate, int months);

Your initial output to the user should be something like this:

Credit card interest
Enter: initial balance, monthly interest rate as
a decimal fraction, e.g. for 1.5% per month write 0.015
and the number of months the bill has run.
I will give you the interest that has accumulated.
100 .1 2

Interest accumulated = \$21.00
Y or y repeats, any other character quits
y

Credit card interest
Enter: initial balance, monthly interest rate as
a decimal fraction, e.g. for 1.5% per month write 0.015
and months the bill has run.
I will give you the interest that has accumulated.
100 .1 3

Interest accumulated = \$33.10
Y or y repeats, any other character quits
n

double interest (double initBalance, double rate, int months);

Thank you very much,

Debbie Bremer

2. The prototype looks good. Surely you can program a function that compounds interest.

3. I dont know how to type in the code for coompound interest. Basically right now, I have the program to display the instructions...but as far as the math goes for interest...im confused. Can anyone help?

4. Google for "compound interest calculation", perhaps?

--
Mats

5. How would you calculate it by hand? Write it out in non-code, then put it in code.

6. Example:
Code:
```#include <cmath>

double interest (double initBalance, double rate, int months)
{
return initBalance * pow(M_E, rate*months);
}```
This will do continuously compounded interest... but I am no economics expert so its the formula I know better. Of course this is a start, and just a mere example since this is NOT the formula you were asked to use.

7. For some reason I cannot get my math to work.

This is what I have so far:

Code:
```#include <iostream>
using namespace std;
int main ( )
{
int months, count = 1;
double init_Balance, rate, interest = 0, new_balance, total_Interest = 0, int_Accumulated;
char repeats;

do
{
total_Interest = 0;
{
cout << " Credit card interest\n ";
cout << "Enter: Initial balance, monthly interest rate as a decimal fraction, e.g. for 1.5&#37; per month write 0.015, and the number of months the bill has run.\n ";
cout << "I will give you the interest that has accumulated.\n ";

cin >> init_Balance, rate, months;
}
for ( int count; count <= months; count++)
{

interest = ( rate * init_Balance );

new_balance = ( init_Balance + interest );

total_Interest = ( interest + );
cout << count ++;

}

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "Interest accumulated = \$\n";
cin >> int_Accumulated;

cout << "Y or y repeats, any other character quits. ";

}while ( repeats != 'Y' && repeats != 'y' );

return 0;
}```

10. Well? Edit your original post and indent.

11. Code:
```

#include <iostream>
using namespace std;
int main ( )
{
int months, count = 1;
double init_Balance, rate, interest = 0, new_balance, total_Interest = 0, int_Accumulated;
char repeats;

do
{
total_Interest = 0;
{
cout << " Credit card interest\n ";
cout << "Enter: Initial balance, monthly interest rate as a decimal fraction, e.g. for 1.5&#37; per month write 0.015, and the number of months the bill has run.\n ";
cout << "I will give you the interest that has accumulated.\n ";

cin >> init_Balance >> rate >> months;
}
for ( int count; count <= months; count++)
{

interest = ( rate * init_Balance );

new_balance = ( init_Balance + interest );

total_Interest = ( interest +  );
cout << count ++;

}

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
{
cout << "Interest accumulated = \$\n";
cin >> int_Accumulated;

cout << "Y or y repeats, any other character quits. ";
}
}while ( repeats != 'Y' && repeats != 'y' );

return 0;
}```

12. The code I just posted will not compute my math in the program. can anyone help me fix my problem?

13. You don't initialize count in the for-loop, which means it has a pretty much random initial value - very likely more than months, so the loop never runs.

14. im a little confused by what you mean. does that mean i usea different variable there?

also, im not even sure if my math equations are right?

15. Code:
`for ( int count; count <= months; count++)`
Should be:
Code:
`for ( int count = 0; count <= months; count++)`
Also, if you want to execute the loop once for every month, you need to compare with <, not <=.

Code:
`total_Interest = ( interest +  );`
This line is meaningless and syntactically incorrect.

Code:
`new_balance = ( init_Balance + interest );`
You overwrite new_balance every iteration without ever doing anything to the value.

Page 1 of 2 12 Last