Please Scroll Down to See Forums Below
napsgear
genezapharmateuticals
domestic-supply US-PHARMACIES UGL OZ
Raptor Labs UGFREAK OxygenPharm
napsgeargenezapharmateuticals domestic-supplyUS-PHARMACIES UGL OZUGFREAKRaptor LabsOxygenPharm

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");

}
 
now what the hell is all that? Man, we talking about about a math problem. that is too much shit right there.

LOL
 
oubeta said:
Nevermind that got a little fucked when I cut and pasted it.

I'll say.


Shit, that didn't have one thing of the problem we have in it.
 
It's a math problem relating to sales of differnt computer models.
Shouldn't be that hard to delete and modify it to your needs if you know the equation. I think I have a few more that are geared more to what you are doing.
 
THE PROBLEM IS NOT IN THE COMPUTER PROGRAM, BUT THE MATH!!!&*($#($&#
 
didn't read the whole post. shouldn't be too hard to figure out.
Le me know if you need help with the C part. I got a C in most my math classes..lol
 
I know the formulas...

Let

L = amount of loan
i = monthly interest rate (so assume the APR has been divided by 12 already)
n = number of payments
R = amount of each level payment

Then

R = L * i / (1 - v^n)
where v = 1/(1+i)

total amount of all payments = n * R
total interest paid = n * R - L
 
thats the exponential compounding function formula, I didnt recognize the way he presented it in his post. Now it makes sense
 
  • Like
Reactions: AAP
Honey Roasted said:
I know the formulas...

Let

L = amount of loan
i = monthly interest rate (so assume the APR has been divided by 12 already)
n = number of payments
R = amount of each level payment

Then

R = L * i / (1 - v^n)
where v = 1/(1+i)

total amount of all payments = n * R
total interest paid = n * R - L


I will try it this way... one question... what is the "^" part of the formula? What math operand is this to be included?
 
AAP said:



I will try it this way... one question... what is the "^" part of the formula? What math operand is this to be included?

^ is the sign that the next number is a exponent.
 
AAP said:


Ok, one last request.... this was great info... can you plug the numbers in there and post a sample string?

C++ coders be gentle...this is the first C++ code I've written in a long time. This should get him going - it spit out the right values when I ran it:




// mathcons.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "math.h"

int main(int argc, char* argv[])
{


// 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
// Payment = Rate * (1 + Rate)N / ((1 + Rate)N -1) * L

double Loan;
double Interest;
double NumPayments;
double PaidBack;
double InterestPaid;
double Payment;

Loan = 10000;
Interest = .01;
NumPayments = 36;


Payment = Interest * pow(1 + Interest,NumPayments) / (pow(1 + Interest,NumPayments) -1) * Loan;
PaidBack = NumPayments * Payment;
InterestPaid = PaidBack - Loan;

printf("Payment \t%f",Payment);
printf("\n");
printf("Interest Paid \t%f",InterestPaid);
printf("\n");
printf("Amount Paid \t%f",PaidBack);

return 0;
}

 
Last edited:
in case ya missed it, the pow function is for raising something to a power i.e., pow (3,2) = 9
 
jnuts said:
in case ya missed it, the pow function is for raising something to a power i.e., pow (3,2) = 9



that is the prob right there..... the pow function. I simply could not figure out how to get the powers raised. Ok, get this... he is doing the problem for Chapter 3. There was NO pow function in Ch 3. They started that in Ch 4.
 
i might have this project saved on my computer.

we had to do the same thing freshmen year. let me look.
 
p0ink said:
i might have this project saved on my computer.

we had to do the same thing freshmen year. let me look.


If you do, do you have the rest of them saved as well?
 
this is going to be harder than i thought, since i gave all of my assignments names like 'pigfucker' and 'fuckingkillme'.

i HATED that class.
 
p0ink said:
this is going to be harder than i thought, since i gave all of my assignments names like 'pigfucker' and 'fuckingkillme'.

i HATED that class.

share what you got. you can email them to me if you wish. I will give them to him to review
 
i'll see what i can do. i'll have to take my name and shit out of them.

i dont know how many, if any, of these projects you will be doing. my professor was one hardcore programmer. he is one of the original developers of emacs. the guy is a fucking genius, which made it extremely hard on the rest of us.

our section of CS1300 was doing graphical shit, reading and recording from other files, etc, while the other section of CS1300 was doing SIMPLE shit. i mean, their final project was similar to what we did for our 4th assignment. it was bullshit, and i got the fucking shaft.
 
I DONT KNOW ANYTHING ABOUT WRITING A PROGRAM BUT THAT IS SOME SIMPLE SHIT (THE FINANCE STUFF, NOT THE PROGRAM).
 
Top Bottom