Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,928 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,836 people online right now. Registration is fast and FREE... Join Now!




Iterative methods!

 
Reply to this topicStart new topic

Iterative methods!, finding apr

hogben45
11 Mar, 2008 - 06:26 PM
Post #1

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 25

My current project is to calculate the annual percentage rate(apr) when given the amount borrowed(p), months (n), and the monthly payment (ann). I am supposed to use iterative methods which we have not gone over in class. I need to determine the apr when given p = 25000 n = 48 and ann = 601. I know I need to set apr = 0 initially, but what after that? To prove I have at least tried, I will post what I have which is not enough to really work from, but I've been working for hours just trying to figure this out, as it is due tomorrow(Wed). Any help would be greatly appreciated.

CODE



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

main()

{

double p , n , apr , x , ann;

p = 25000.;

n = 48.;

ann = 601.;

x = apr / 1200.;

apr = 0;

ann = p * x * (pow((1. + x) , n)) / (pow((1. + x) , n) - 1.);

printf("\napr is %f" , apr);

system("pause");

}



I have attached my project sheet just in case I have not explained it well enough. Thank you so much.





Attached File(s)
Attached File  Graded_program_4_SP_2008.rtf ( 46.04k ) Number of downloads: 11
User is offlineProfile CardPM
+Quote Post

hogben45
RE: Iterative Methods!
15 Mar, 2008 - 09:08 AM
Post #2

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 25

I have come along way with this project. Here is my latest code. As of now, it is fully functional by pulling the first 3 values from my data file. I need the program to pull out all values from the data file in sets of 3. How would I make the program to continue to pull out the next three values, and the next, until no more values remain in the data file? Thanks alot.

CODE



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

    void calc();

    main()

    {

    printf("\n\nThis program is the work of Ben Hogan, I.D. #211");

    calc();

    }
/******************************************************/
    
    void calc()

    {

    double p , n , apr , x , ann , mon;

    FILE *infile;

    infile = fopen("program_4.dat" , "r");

    fscanf( infile , "%lf %lf %lf" , &p , &n , &mon );

    apr = 0.;

    ann = 0.;

    while (ann <= mon)
    {

        apr = apr + .02;
    
        x = apr / 1200.;
    
        ann = p * x * (pow((1. + x) , n)) / (pow((1. + x) , n) - 1.);

    }

    printf("\n\nLoan Amount     Months     Payment Amount     Est. Apr(%)\n");
    printf("%8g%12g%14g%18g\n\n", p , n , mon , apr);  

    system("pause");

    }


I have attached the data file.


User is offlineProfile CardPM
+Quote Post

hogben45
RE: Iterative Methods!
16 Mar, 2008 - 03:03 PM
Post #3

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 25

Could someone please help me with this program. I think I'm going in the right direction...
CODE



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

    void calc();

    main()

    {

    printf("\n\nThis program is the work of Ben Hogan, I.D. #211");
    
    calc();

    }
/******************************************************/
    
    void calc()

    {

    double p , n , apr , x , ann , mon;
    int flag;

    FILE *infile;

    infile = fopen("program_4.dat" , "r");

    flag = fscanf( infile, "%lf %lf %lf" , &p , &n , &mon);

    apr = 0.;

    ann = 0.;

    while (1 == flag)

    {
        apr = apr + .02;
    
        x = apr / 1200.;
    
        ann = p * x * (pow((1. + x) , n)) / (pow((1. + x) , n) - 1.);

    flag = fscanf( infile, "%lf %lf %lf" , &p , &n , &mon);

    }

    printf("\n\nLoan Amount     Months     Payment Amount     Est. Apr(%)\n");
    printf("%8g%12g%14g%18g\n\n", p , n , mon , apr);

    system("pause");

    }


Thanks in advance.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:28PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month