1. ## interest formula

good evening all, im in the process of writing a code that will calculate loan payments. I made the equation for the interest formula, but when I compile it, I get the error:
"called object is not a function"

Code:
```void calc_loan(char*loan_amount, char*apr, char*loan_term, float *payment)
{

float i = (*apr/12);
float x = (1+i);
*payment = *loan_amount(i ((pow((x), *loan_term)))/((pow((x), *loan_term) -1)));

}```
I tried to simplify the equation as much as I could, and from what i can tell it should be right. Anyone see something I missed? Thanks in advance.

2. Code:
`loan_amount(`
this is function notation, but loan_amount is C-string, what do you want to do with it?
also

pow(x, *loan_term)
x is double and *loan_term is one char are you sure it is what you want to do?

3. > *loan_amount(
There is no operator between this variable and the (, so the compiler thinks it is a function call.

Also, a char isn't large enough for storing the kinds of numeric values like a loan amount.

4. Well its supposed to work where the user is asked to input a bunch of information, of which include loan amount. Then I want the loan amount, apr, and loan term that the user inputs to be plugged into this interest formula. Here is the entire code to give you an idea of what im going for:

Code:
```void calc_loan(char*loan_amount, char*apr, char*loan_term, float *payment)
{

float i = (*apr/12);
float x = (1+i);
*payment = *loan_amount*(i* ((pow((x), *loan_term)))/((pow((x), *loan_term) -1)));

}```

5. Originally Posted by Salem
> *loan_amount(
There is no operator between this variable and the (, so the compiler thinks it is a function call.

Also, a char isn't large enough for storing the kinds of numeric values like a loan amount.
So I should change it to float*loan_amount?

6. I suggest you read how to get a number from the user in C first, then you should change loan_amount to a double (or a float but you will lose precision).

Also, please be aware that, if you have an array (a C string in your case), then the name of the array is already a pointer to the first element. In that case, either is correct:

Code:
```char myString[128];
myFunctionCall(myString);

// or

myFunctionCall(&myString[0]);

// or

myFunctionCall(&(*myString));```

Furthermore, it is very good that you are using fgets to read a string from the user, you could improve your code though by checking the return value from fgets. As explained here, you can check if fgets executed correctly and you should also test and remove the newline character:

Code:
```  char buf[BUFSIZ];
char *p;

printf ("Please enter a line of text, max &#37;d characters\n", sizeof(buf));

if (fgets(buf, sizeof(buf), stdin) != NULL)
{
printf ("Thank you, you entered >%s<\n", buf);

/*
*  Now test for, and remove that newline character
*/
if ((p = strchr(buf, '\n')) != NULL)
*p = '\0';

printf ("And now it's >%s<\n", buf);
}```
You can even put it all within one function:

Code:
```int getString(char buf[], size_t bufSize)
{
char *p;

printf ("Please enter a line of text, max %d characters\n", bufSize);

if (fgets(buf, bufSize, stdin) != NULL)
{
if ((p = strchr(buf, '\n')) != NULL)
*p = '\0';
return 0;
}
return 1;
}```
The function takes as argument the C-String and the size of that string (since sizeof within the function would return the size of the pointer only) and it returns 0 if it could read a string and 1 in the other case.

7. > fgets(line, 500, stdin);
> sscanf(line, "&#37;s", loan_amount);
> printf("\n");
Yes, you probably need some kind of numeric data types for these (the rest seem fine as strings).

So perhaps the parameter would be
double *loan_amount

And to convert it
sscanf( line, "%lf", loan_amount );

You should check the return result of sscanf, and in particular, check that the %s conversions really will fit into the intended strings.

> char last_name[26], first_name[26], address[26], city_state[26];
> char phone_number[9], account_number[9], loan_amount[9], apr[9],
> loan_term[9];

> information (&*account_number, &*last_name, &*first_name, &*address,
> &*city_state, &*phone_number, &*loan_amount, &*apr, &*loan_term);
Too many & and *
Say you want the first 6 as strings, and the last 3 as doubles.
Code:
```    char last_name[26], first_name[26], address[26], city_state[26];
char phone_number[9], account_number[9],
double loan_amount, apr, loan_term;

city_state, phone_number, &loan_amount, &apr, &loan_term);```
You only need the array name to pass an array to a function. The "&*" is the same, but they just cancel each other out.

The prototype for the function being
Code:
```void information(char *account_number, char *last_name, char *first_name,
char *address, char *city_state, char *phone_number, double *loan_amount,
double *apr, double *loan_term)```

8. Thanks again for all the input, I took all your advice and modified my code a bit. Last thing I need it to do is print out each month and the interent, principal and remaining balance to go along with it. And the all the inputs for loan_amount, apr, and loan_term are being printed out at the end. Perhaps this is where the problem lies?

9. Im looking for an output similar to this:

Customer #: 0000001234
John Doe
205 E 5th Ave
New York, New York
(563)563-5639
-------------------------------------------------------------------------
Loan Amount: \$10000.00 APR: 120.00% Period: 24
-------------------------------------------------------------------------
Pay # Payment Principal Paid Interest Paid Remaining Balance
1 1113.00 113.00 1000.00 9887.00
2 1113.00 124.30 988.70 9762.70
.
.
.
23 1113.00 919.83 193.16 1011.82
24 1113.00 1011.82 101.18 0.00
-------------------------------------------------------------------------
Customer Totals:
Total Paid: \$26711.95 Interest Paid: \$16711.95

10. Call calc_loan inside your for loop which prints each payment

11. Okay heres what I did now:

Code:
```for(n=0;n<=loan_term;n++)
{
if(n%12==0)
{ k++;
printf("%4d\t%10.2f\t  %6.2f\t   %10.2f\t   %10.2f\n",loan_term, payment, *ATI,*ATP,*RP);
}
}```
It seems to be working, but Ill im getting is zeros because the loan_term, interest, and loan_amount are being recorded correctly. At the end where it displays them, all I get is zeros for all of the instead of the actual numbers the user puts in..

12. You're still not calling calc_loan inside the loop.

> printf("%4d\t%10.2f\t %6.2f\t %10.2f\t %10.2f\n",loan_term, payment, *ATI,*ATP,*RP);
To print a float, drop the *'s on ATI etc.
You have to be very careful about passing parameters to printf/scanf functions because there is absolutely no error checking.

If you're using gcc, then you can add
-W -Wall -ansi -pedantic
to the compiler options, and that will diagnose many typical programming problems, including printf/scanf parameter mis-matches.

13. Okay I got it to work and I got the format down and everything, but it doesnt update the payments as the month increases?

Code:
```
for(n=1;n<=loan_term;n++)
{
calc_loan (&loan_amount, &apr, &loan_term, &payment, &ATI, &ATP, &RP);
printf("&#37;4d\t%10.2f\t  %6.2f\t   %10.2f\t   %10.2f\n", n, payment, ATI, ATP, RP);
}```

14. You need to adjust the loan amount inside the loop as well
Perhaps
loan_amount -= ATP;

15. Ah that got it working, thank you sir.