Please Scroll Down to See Forums Below
napsgear
genezapharmateuticals
domestic-supply
puritysourcelabs
UGL OZ
UGFREAK
napsgeargenezapharmateuticals domestic-supplypuritysourcelabsUGL OZUGFREAK

C++ and Math Experts... need help

AAP

Plat Hero
Platinum
my neighbor (the kid taking C++ this summer at the tech school) needs help.

Ok, heres the problem.... he has to write a program to calculate the simple interest of a loan payment. The instructions are not very clear on where the variable are coming from. The interest amount I get and what the book lists are too different ones. (I am doing paper math here.)

Here is the program list:

The monthly payment on a loan may be calculated by the following formula:

Payment = Rate * (1 + Rate)N / ((1 + Rate)N -1) * L

Rate is the monthly interest rate, which is the annual interest rate divided by 12. (A 12 percent annual interest would be 1 percent monthly interest) N is the number of payments and L is Loan Amount. Write a program that asks for these values and displays a report similiar to :

Loan Amount: $ 10000.00
Monthly Interest Rate 1%
Number of Payments 36
Monthly Payment 332.14
Amount Paid Back 11957.15
Interest Paid 1957.15



Ok, for the life of me.. I can not get that math formula to work. The interest rate I get whether doing a flat rate or variable rate (it doesn't say which, so I tried each) will not work with those figures.

Can someone help? Big karma slam to everyone.
 
AAP said:
Are all of your variables declared as 'float' or 'double'? Sorry I don't know much about the formula, but I can figure out why a formula wouldn't work in C++.

If that's what you think it is, post the exact syntax of the formula in your code, along with the types of variables you are using.

I'm goiing to get some lunch... back later.
 
That above IS the program.... he has all the necessary structure and all, the variable definitions, the prompts, etc... it is just the math formula for computing the interest rate is throwing us off.

If he can figure out how to compute the interest rate, he can put it in the program. Writing the program is the easiest, it is just getting that damn formula to give you the numbers that they (I) posted.
 
Only the source of that formula knows whether its correct or not. Have him check in the book or with his teacher... it can be anything! LIke parenthesis in wrong place and mixed up variables
 
Also don't forget that a monthly 1% Interest is NOT 12% yearly interest. You can't just multiply it by 12, because the interest gets compounded every month.
 
supernav said:
>I can not get that math formula to work.

forget the C program. Do the calculatios first by hand on a calculator. If they are incorrect there, that's your problem. If not, then in C write the same logic steps as u did in your calculator. Break it down line by line if u must and step through it. That's a skill as necessary in C just as important as learning the syntax of it all.

-= nav =-

BINGO!!! that is what I was trying to say. We are not concerned about the C program yet.... it is just the math formula on paper and the calculator will not work.

Can someone work that formula and get the results?

It is a 10000 loan amount, 1% interest monthly, 36 months of payments... monthly payment is 332.14. The total amount of interest is 1957.15 and the total having to be paid back will equal 11957.15. This is the math formula I can't get to work.
 
This is a simple program I did a while back. I wrote it in C and might give you an idea of the structure. I think I have a few math equations for the diameter of a circle and similar in C++ I'll try to dig up.

#include <stdio.h>

void main()
{
int model_code=0;
int qty_ordered=0;
int cust_id_number=0;
int exit_code=0;
float unit_price=0;
float gross_sales_amount = 0;
float price1 = 0;
float price2 = 0;
float price3 = 0;

printf("Enter Customer ID Number");
printf("\n");
scanf("%d", &cust_id_number);

printf("\n");
printf("Enter exit_code");
printf("\n");

printf("Please enter:");
printf("\n");

printf("1 - to purchase");
printf("\n");

printf("9 - to Exit sale for your total amount");
printf("\n");

scanf("%d", &exit_code);

exit_code = model_code;

while (exit_code !=9) {

printf("\n");
printf("Enter model_code");
printf("\n");
printf("Please enter");
printf("\n");
printf("1 - for Professional model");
printf("\n");
printf("2 - for office model");
printf("\n");
printf("3 - for student model");
printf("\n");
printf("9 - to Exit sale for your total amount");
printf("\n");

scanf("%d", &model_code);

if (model_code == 1) {

printf("Enter qty_ordered");
printf("\n");
scanf("%d", &qty_ordered);

if (qty_ordered >10) {
unit_price = 1450 - (0.2*1450);
}
else {

unit_price = 1450;
}

price1 = price1 + (unit_price * qty_ordered);
}

else if (model_code == 2) {
printf("Enter qty_ordered");
printf("\n");
scanf("%d", & qty_ordered);

if (qty_ordered >15) {
unit_price = 1100 - (0.10*1100);

}
else {
unit_price = 1100;
}
price2 = price2 + (unit_price * qty_ordered);
}
else if (model_code == 3) {
printf("Enter qty_ordered");
printf("\n");
scanf("%d", & qty_ordered);

unit_price = 835;
price3 = price3 + (unit_price * qty_ordered);

}

else if (model_code ==9) {
exit_code = 9;
}

else{
printf("\n");
printf("please enter a valid model code");
printf("\n");

}

}
gross_sales_amount = price1 + price2 + price3;
printf("\n");
printf("For the customer ID# %d", cust_id_number);
printf("\n");
printf("\nThe total price for professional model is : %f", price1);
printf("\nThe total price for office model is : %f",price2);
printf("\nThe total price for student model is : %f",price3);
printf("The gross_sales_amount is %f", gross_sales_amount);
printf("\n");

}
 
Top Bottom