Computer Science Canada array help |
Author: | mendem03 [ Wed Jun 02, 2010 12:15 pm ] | ||
Post subject: | array help | ||
How do i get the arry value into the loop when im multiplying. interestRate is the array, i want to multiply with the amount. I really need help with this. |
Author: | DemonWasp [ Wed Jun 02, 2010 1:31 pm ] | ||
Post subject: | RE:array help | ||
Perhaps you should index it with interestPeriod, instead of a hard-coded number (1,2,3) like you have above. For example:
|
Author: | mendem03 [ Wed Jun 02, 2010 3:35 pm ] | ||
Post subject: | Re: array help | ||
i made an adjustment and i need help with this one
I gave interestRate values to the user and depending on want they pick they will get the value but now im trying to use that value for a calculation but i dont know how to get it to work. Im trying to do the calculation in the loop. Can someone try the program and help me please. |
Author: | yoursecretninja [ Thu Jun 03, 2010 4:43 pm ] |
Post subject: | Re: array help |
I just peaked at the stuff pertaining to the interest rate. Why are you using an array for interest rates? You ask the user to choose an amount of money to borrow. The entered amount of money is compared against three ranges of values. For amount within range A you set the value of interestRate at index 0. For amount within range B you set the value of interestRate at index 1. For amount within range C you set the value of interestRate at index 2. moving along to the part just before you perform your calculations in that for loop... You create an integer called interestRate2 and assign it the value of one. You then assign the value of InterestRate at index interestRate2 to the value of interestRate2... do you see what you did there? You then calculate the interest payment as amount * ((the value of interestRate at index interestRate2 / 100) + 1). Does following this logic in plain english, rather than looking at code, help you see why you'll get the wrong answer every time you run the program (assuming the program actually compiles and runs)? Do you see what you are doing when you operate on that array? Do you see how this problem would be much easier if you used an integer to hold the interest rate instead of an array? I hope this is helpful... I'd like to help you understand how to fix this rather than just fixing it for you as this looks like it might be a homework assignment. |