ok, i'm new to c++, please bear with me........

i have a program... it asks the user to enter the price, then it asks to enter the interest rate from, and then interest rate to, and then the loan period (> 2 years)

The formula used is:

result = price * pow(1+annual rate of interest/100/365, loan period *365)

it should be desplayed like this:

              8%             9%               10%
Year 2    result           result            result
year 3    result           result            result
.
. 
year 4    result           result            result

the preceding was if: interest rate from was 8, and interest rate to was 10, and if the user entered 4 for the loan period.......so it basically needs to calculate the result for each percentage and for each year ofcourse......how do i do this using for loop....thanks alot for your help..........this is what i've done so far:

int year, price, intratefrom, intrateto, x, y, loanp;
    double CPL;

    printf("\n");
    printf("Car Loan Financing\n\n\n");
    printf("Please enter price of car:");
    scanf("%d", &price);
    printf("\nPlease enter interest rate (integer %) from          :");
    scanf("%d", &intratefrom);
    printf("Please enter interest rate (integer %) to            :");
    scanf("%d", &intrateto);
    printf("Please enter loan period, from 2 years to (integer) :");
    scanf("%d", &loanp);
    printf("\n\n");

    SO THIS IS WHERE I"M STUCK, I"VE TRIED USING FOR BUT IT JUST DESNT DISPLAY RIGHT(CPL assigned is the result)  ACTALLY ALL THIS CALCULATION AND DISPLAY should be DONE IN THE FUNCTION which i named financing(), i dont know how to do that in the new function without using global variables :( :

             for( x = intratefrom; x <= intrateto; x++){


        for(year = 2; year <= loanp; year++){



        }
    }
    financing(); //call the function financing
}

Well here is an idea.. didn't test just wrote it from the head.. It might be buggy.

#include <stdio.h>
#include <stdlib.h>

int * intcalc(int,int,int,int);
int * intcalc (int price, int rate1, int rate2, int period)
{
int result[2]={0,0};//declares and initializes
for (int i=0; i<(period+1); i++)
{
result[0] =0;//whatever the way you calc for each year (rate1)
}
for (int i=0; i<(period+1); i++)
{
result[1] =0;//whatever the way you calc for each year (rate2)
}
return result;
}

void main ()
{
for (;;)
{
int rate1, rate2, period, price;

printf ("Enter data:\n");
fflush (stdin);  //flushing scanf buffer.. don't have to do it
scanf ("%d",&price);
scanf ("%d",&rate1);
scanf ("%d",&rate2);
scanf ("%d",&period);
int * result = intcalc(price, rate1, rate2,period);
printf ("\nresult1=%d, result2=%d\n",result[0], result[1]);
system("PAUSE");
}
}
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.