# Thread: cant figure out where to start

1. ## cant figure out where to start

hi i have the "Starting out with C++" by Tony Gaddis 2nd Ed. and cant find the floppy is there a place u can download whats on it?..........my main problem is with chapter 3, page 151, Programing Challenge #13

its shows this formula

payment = Rate * (1+Rate)^n * L
((1+Rate)^n-1)

and i am asked to make a program that asks for "n" , Rate, and "L" and displays a report simliar to this one
Where; Rate = Interest rate, N=Number of payments, and L=Amount of the loan

Loan Amount: \$10000.00
Monthly Interest Rate: 1%
Number of Payments: 36
Monthly Payment: \$ 332.24
Amount Paid back: \$11957.00
Interest Paid: \$ 1957.00

I cant figure out how to write the formula to get what it asks for? any ideas........i was thinking i use "POW"? but cant seem to find in my book anywhere if just gives the above example, since this is for class i dont want a complete answer......just alittle help figuring out how to use the formula.

thanks

2. you'll have to use some sort of pow()

its in math.h

n to the power of 2 is
pow(n,2);

3. haha i feel stupid i think i got it tell me if u think there is a easier way to write this

M =((Rate2 * pow(1+Rate2,N))/(pow(1+Rate2,N)-1))*L;

4. not that i can see.

5. okie here's a tuff one for ya.........i got it all made an it works great .........but how do i get all the numbers to line up
EX.

first day: 342
second day: 234
third day: 533

something like that? i have tried all the SetIos flags i can think of an no change

6. Originally posted by ii3ejoe
haha i feel stupid i think i got it tell me if u think there is a easier way to write this

M =((Rate2 * pow(1+Rate2,N))/(pow(1+Rate2,N)-1))*L;
I don't know if it'd be easier, but you could set the elements of the formula to variables and then use the formula.
double x = 1 + Rate2;
double y = pow(x, N);
double z = Rate2 * y;
and so on, so the top half of the formula would be M = z/(same type of thing bottom half). This may not be easier, but might be clearer to read.

7. Originally posted by ii3ejoe
okie here's a tuff one for ya.........i got it all made an it works great .........but how do i get all the numbers to line up
EX.

first day: 342
second day: 234
third day: 533

something like that? i have tried all the SetIos flags i can think of an no change
Offhand, use setw(x) to cout the day followed by setw on the number. setw only works on the next value output. Something like:
cout << setw(12) << "first day: " << setw(5) << num;

Popular pages Recent additions