Loan calculator in C I wanted to create a loan calculator, but the code I could think of was using 3 functions, and calling them and getting result. But I felt it was easy but bad code because I thought this can be written in fewer lines and with more quality. I wanted to ask what are some things to keep in my mind while trying to write better code instead of going in flow and creating many functions.

#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;math.h&gt;

float loanAmount,interestRate,Discount,i,loanPayment; //global variables

int years;

void loanDetails(void); //input from user regarding the loan
float annualRate(void);// interest rate 
float discount(void); //discount to be added

int main() //main
{

    loanDetails(); //called three functions
    annualRate();
    discount();

    loanPayment = (loanAmount)/(Discount); //formula for monthly payments

    printf("\nthe monthly loan payment is %f",loanPayment);

    return EXIT_SUCCESS;
}

void loanDetails(void) //taking input from user
{
    printf("please enter Total Loan Amount: ");
    scanf("%f",&amp;loanAmount);
    printf("please enter the number of years: ");
    scanf("%d",&amp;years);
    printf("please enter the annualrate to be applied: ");
    scanf("%f",&amp;interestRate);
}

float annualRate(void) //calculated annual rate
{
    float *ann;
    ann = &amp;interestRate;
    i = ((*ann)/(100))/12;
    printf("the value for %d years is %f",years,i);
    return i;
}

float discount(void) //calculated dicount
{    
    float *x,y;
    x = &amp;i;
    y = 1 + *x;
    int n = years*12;

    float topD = (pow((y),n)-1);
    float botD = (y-1)*pow((y),n);
    Discount = topD/botD;
    printf("\nthe value of discount is : %f",Discount);
    return Discount;
}
There are a few things to note here. There is extensive referencing and dereferencing of variable addresses, which makes the code less clear. For example, float *x,y; x = &amp;i; y = 1 + *x;.  This is unnecessary and seems imposed by thinking related to your use of global variables. 

There is nothing wrong with passing pointers as arguments to functions, rather than using global variables. 

There is also nothing wrong with using functions. The code below is clearer. Additionally, it removes the need for the function "annualRate," as that is simply a division. 

#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt; 
#include&lt;math.h&gt;

void loanDetails(float * loanAmount, int * years, float* interestRate);
float discount(int years, float i);



int main (void) {
    float loanAmount, interestRate, disc;
    int years;

    loanDetails(&amp;loanAmount, &amp;years, &amp;interestRate);
    disc = discount(years, interestRate/1200);

    printf("\nthe value of discount is : %f",disc);


    printf("\nthe monthly loan payment is %f",loanAmount/disc);
    return EXIT_SUCCESS;
}

void loanDetails(float * loanAmount, int * years, float* interestRate) {
    printf("please enter Total Loan Amount: ");
    scanf("%f",loanAmount);
    printf("please enter the number of years: ");
    scanf("%d",years);
    printf("please enter the annualrate to be applied: ");
    scanf("%f",interestRate);
}
float discount(int years, float i) {
    int months = years*12;
    return (pow((1+i),months)-1)/((i)*pow((1+i),months));
}


If you wanted no functions other than main, you could do the following. Essentially, move the code from the functions to main. This is appropriste, considering that the code is not repeated, runs sequentially, and does not have varied/multiple inputs. 

#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt; 
#include&lt;math.h&gt;


int main (void) {
    float loanAmount, interestRate, disc, i;
    int years, months;

    printf("please enter Total Loan Amount: ");
    scanf("%f",&amp;loanAmount);
    printf("please enter the number of years: ");
    scanf("%d",&amp;years);
    printf("please enter the annualrate to be applied: ");
    scanf("%f",&amp;interestRate);

    months = years*12;
    i = interestRate/1200;

    disc = (pow((1+i),months)-1)/((i)*pow((1+i),months));

    printf("\nthe value of discount is : %f",disc);

    printf("\nthe monthly loan payment is %f",loanAmount/disc);
    return EXIT_SUCCESS;
}