``````#include<stdio.h>
#include<math.h>

# define I 0.0765    //Interest Rate
char fname[20];
char lname[20];
float loan = 0.0;
int years;
double PB;

//Prototypes
double Mortgage_Calc(void);
void Financial_Report(void);
int main() {

printf("  *******************Caribbean Mortgage Company*************\n\n\n\n\n");

printf("Enter the Customer's Name (First Name and Surname)\n");
scanf("%s%s",fname,lname);

printf("Enter Requested Loan Amount\n");
scanf("%f",loan);

printf("Enter Number of Years for Mortgage\n");
scanf("%d",years);
Financial_Report();
return(0);
}

double Mortgage_Calc(double PB, double A, double Y) {
//PB :payback
//A :Amount Loaned
//Y:Number of Years over which the mortgage extends

PB = A * pow((1 + I), years);

/*A*1.0+ I/100;
A=exp(Y);
PB=A;
years=Y;
principal * pow((1 + rate), (double)years); */
return(PB);
}

void Financial_Report()
{
printf("  *******************Caribbean Mortgage Company*************\n");
printf("  ************************Financial Report******************\n\n\n\n\n");
printf("Applicant's Name: %s %s", fname,lname);
printf("Requested Loan Amount: %f",loan);
printf("Interest Rate: 7.65 percent");
printf("Number of Years for Mortgage: %d", years);
printf("Total Amount to be Paid Back: %f",PB);
// printf("The Monthly Installments are:

}``````

## All 6 Replies

Post your code using code tags ( read the forum announcements )

And what exactly is the problem with the given code. Be specific.

> scanf("%f",loan);
You forgot the &, like `scanf("%f", &loan);` Ditto for the years.

You also need to call your Mortgage_Calc function at some point.

1. It will run to the point of asking the user of the loan amount and then it will crash.

2. I don't know how to call a function within a function; hence the main is to ask for the information, the information given to go into Mortgage_Calc to be calculated then for the output/calculations to be displayed in the Financial Report.

But i'm at a complete lost.

There can't be any global variables, must be functionally decomposed and modular...and i think that is what i've been doing so far.......

#include<stdio.h>
#include<math.h>

# define I 0.0765 //Interest Rate
char fname[20];
char lname[20];
float loan = 0.0;
int years;
double PB;

//Prototypes
double Mortgage_Calc(void);
void Financial_Report(void);
int main() {

printf(" *******************Caribbean Mortgage Company*************\n\n\n\n\n");

printf("Enter the Customer's Name (First Name and Surname)\n");
scanf("%s%s",&fname,&lname);

printf("Enter Requested Loan Amount\n");
scanf("%f",&loan);

printf("Enter Number of Years for Mortgage\n");
scanf("%d",&years);
Mortgage_Calc();
Financial_Report();
return(0);
}

double Mortgage_Calc(double PB, double A, double Y) {
//PB :payback
//A :Amount Loaned
//Y:Number of Years over which the mortgage extends

PB = A * pow((1 + I), years);

/*A*1.0+ I/100;
A=exp(Y);
PB=A;
years=Y;
principal * pow((1 + rate), (double)years); */
return(PB);
}

void Financial_Report()
{
printf(" *******************Caribbean Mortgage Company*************\n");
printf(" ************************Financial Report******************\n\n\n\n\n");
printf("Applicant's Name: %s %s", &fname,&lname);
printf("Requested Loan Amount: %f",&loan);
printf("Interest Rate: 7.65 percent");
printf("Number of Years for Mortgage: %d", &years);
printf("Total Amount to be Paid Back: %f",&PB);
// printf("The Monthly Installments are:

}
}

1. Use the code tags when posting code. Don't you see the watermark at the back of the compose message window, or are you just choosing to ignore it?

printf("Applicant's Name: %s %s", &fname,&lname);
printf("Requested Loan Amount: %f",&loan);
printf("Interest Rate: 7.65 percent");
printf("Number of Years for Mortgage: %d", &years);
printf("Total Amount to be Paid Back: %f",&PB);

I said put the & on the scanf calls, not then paste it all through the printf calls as well.

scanf("%s%s",&fname,&lname);

Although not so serious, you don't need the & on these, since you're reading into a string. You don't need the & when using %s to read into an address.

Mortgage_Calc();

Would be better written as

``````PB =    Mortgage_Calc();
``````

But since all your variables are global, it's a moot point, and the return statement in the function is pretty much useless.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.