Newbie to C++ needs help plz!!

• 01-22-2008
xuder
Newbie to C++ needs help plz!!
Sorry for bothering yall, I just need help if you dont mind. Im new to c++ programming and I need some help. I tried using other references like some books that i have but they didnt really help.

Title: Interest Earned

Assuming there are no deposits other than the original investment, the balance in a savings account after one year may be calculated as

Amount = Principal * ( 1 + Rate/T ) ^T

where Principal is the balance in the account, Rate is the annual interest rate, and T is the number of times the interest is compounded during a year. (e.g., T is 4 if the interest is compounded quarterly.)

Write a program that asks for the principal, the interest rate, and the number of times the interest is compounded. It should display a report similar to the following:

Interest Rate: 4.25&#37;
Times Compounded: 12
Principal: \$1000.00
Interest: \$43.33
Final Balance: \$1043.33

Here is what I have done but I cant finish because Im getting all these errors
Im using Dev C++ for this.

Heres what i got:

Code:

``` #include <cstdlib> #include <iostream> using namespace std; int main() { double TimesCom = 0.0; double InterestRate = 0.0; double Principal = 0.0; double Interest = 0.0; double FinalBalance = 0.0; cout << "Enter the principal balance in the account: "; cin >> Principal; cout << "Enter the annual interest rate percentage: "; cin >> InterestRate; cout << "Enter the number of times the interest is compounded (months): "; cin >> TimesCom; //This is where i have trouble I tried the using the formula above  Amount(final balance) = Principal * ( 1 + Rate/T ) ^T InterestRate = InterestRate / 100; // This is where i need help I did this to see to find the final balance but it doesnt let me compile because of some problems with it FinalBalance = Principal * (1 + (InterestRate / TimesCom))^TimesCom; //I also tried using the pow to get the TimesCom to the power of the formula like so FinalBalance = Principal * pow(1 + (InterestRate / TimesCom), TimesCom); //but once i get the Final Balance I assume this is how i get the output of the interest Interest = FinalBalance - Principal; cout << "Interest Rate: " << InterestRate << endl; cout << "Times Compounded: "<< TimesCom << endl; cout << "Principal: "<< Principal << endl; cout << "Interest: " << Interest << endl; cout << "Final Balance: " << FinalBalance << endl; system("PAUSE"); return EXIT_SUCCESS; } /* This is what the outcome should be Interest Rate: 4.25% Times Compounded: 12 Principal: \$1000.00 Interest: \$43.33 Final Balance: \$1043.33 */```
Thanks for looking and helping
• 01-22-2008
Daved
You posted in code tags, that's good, but the indenting is still missing making it a bit harder to read the code.

You also didn't post the errors. It will make it easier and faster for someone to spot the error if you paste the exact error messages. At first glance, the code looks fine, including the InterestRate / 100 line.

If you're just having trouble accomplishing the next part, post what you've tried on that (what you think is your best attempt) and it will be easier to help with specific suggestions.
• 01-22-2008
rags_to_riches
Quote:

Originally Posted by xuder
I cant finish because Im getting all these errors

What errors? Are we supposed to be psychic?
• 01-22-2008
xuder
o ok sorry about that ill edit the post
• 01-22-2008
xuder
Ok post is edited

Thanks for helping out I appreciate it!
• 01-22-2008
Cpro
Code:

`#include <cmath>`
in your code, so you can use the "pow" function in this line:
Code:

`FinalBalance = Principal * pow(1 + (InterestRate / TimesCom), TimesCom);`
• 01-22-2008
xuder
Omg Thank you so much!

it compiled fine now!

so I was just missing the #include <cmath>

thank you very much for the help
• 01-22-2008
abh!shek
Quote:

InterestRate = InterestRate / 100;
Why did you divide Interest rate by 100? If the user inputs 4.65 then it will become 0.0465

I think....but I am not sure that the ^ operator is not allowed in C++ (I may be wrong)
You can use loops.
• 01-22-2008
cyberfish
Code:

`I think....but I am not sure that the ^ operator is not allowed in C++ (I may be wrong)`
it is allowed, but for something totally unrelated - it is the operator for exclusive OR.
• 01-22-2008
Daved
>> Why did you divide Interest rate by 100? If the user inputs 4.65 then it will become 0.0465

The interest rate is input as a percentage, but used in the calculations as a normal decimal ratio.
• 01-23-2008
abh!shek
Quote:

The interest rate is input as a percentage, but used in the calculations as a normal decimal ratio.
I still don't get it. If the interest rate is 4.25&#37;, then tell me what I am supposed to put in the formula
Code:

`Amount = Principal * ( 1 + Rate/T ) ^T`
in place of "Rate"?

0.0425 or just 4.25 ?
• 01-23-2008
matsp
You should use 0.0425, since 4.25% is 0.0425 as a "multiplier".

--
Mats