Thread: error declaration terminated incorrectly help

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    error declaration terminated incorrectly help

    here is the program if u could help i would be greatly happy.



    /* Name : Brian Brown */
    /* Class : COSC 1415 */
    /* Assignment : Asg 7 */
    /* Date Due : Nov 25, 2002 */


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

    void PrintHeading (void);

    void loan (void);
    float get_amount (void);
    float get_interest (void);
    int get_term (void);
    float calculate_payment (float a, float rm, int nm);
    void printInfo (float a, float rate, float rm, int ny, int nm,
    float mp);
    void print_amortize (float a, int nm, float rm, float mp);

    int main ()
    {
    PrintHeading();
    loan();

    return 0;

    }

    void loan (void)
    {
    float a;
    float rate;
    int ny;
    int nm;
    float rm;
    float mp;

    a = get_amount();
    rate = get_interest();
    ny = get_term();
    nm = ny * 12;
    rm = rate/nm;
    mp = calculate_payment (a, rm, nm);
    printInfo (a, rate, rm, ny, nm, mp);
    print_amortize (a, nm, rm, mp);

    }

    float get_amount (void)
    {
    float a;

    printf("Please enter amount of loan: ");
    scanf("%f", &a);

    return a;

    }

    float get_interest (void)
    {
    float rate;

    scanf("%f", &rate);
    printf("Please enter an interest rate: ");
    scanf("%f", &rate);

    return rate;

    } /*end get_amount */

    int get_term (void)
    {
    int ny;

    scanf("%d", &ny);
    printf("Please enter term of the loan: ");
    scanf("%d", &ny);

    return ny;

    }

    float calculate (float a, float rm, int nm)
    {

    float p;
    float Q;
    float mp;


    p = pow((1 + rm), nm);
    Q = p/(p - 1);
    mp = a * rm *Q;

    return mp;

    }

    void printInfo (float a, float rate, float rm, int ny, int nm,
    float mp);
    {

    printf("The amount of the loan (principal): %6.2f", a);
    printf("\nInterest rate/year (percent): %4.1f", rate);
    printf("\nInterest rate/month (decimal): %5.6f", rm);
    printf("\nNumber of years: %6d", ny);
    printf("\nNumber of months: %6d", nm);
    printf("\nMonthly payment: %6.2f", mp);
    printf("\n Old Monthly Interest Principal New");
    printf("\nMonth Balance Payment Paid Paid Balance");


    }


    void print_amortize (float a, int nm, float rm, float mp)
    {
    int month;
    OldBalance = a;

    for(month = 1; month <= nm, month++)
    {
    InterestPaid = OldBalance * rm;
    PrincipalPaid = mp - rm;
    NewBalance = OldBalance - Principal;

    Printf("%5d %9.2f %9.2f %9.2f %9.2f\n");
    OldBalance = NewBalance;
    }

    return 0;

    }


    void PrintHeading (void)
    {
    printf("Name : Brian Brown\n");
    printf("Class : COSC 1415\n");
    printf("Assignment : lab 7\n");
    printf("Date Due : Nov 25,2002\n");
    printf("\n");


    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    help

    could some one run this and tell me what i did wrong i really need to learn this

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    I'm doing that now.

    First problem, I don't know C, though I'm faking it.

    Second problem, you've got numerous errors in your code that you should have caught on your own. Silly stuff, really.

    Third, I don't know C. (Did I mention that?)

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    well thx for the help

    i am new bie and this program has been giving me a headache

    for the last week

    i cant debug it

    i was told if i tried u guys would be glad to help me

    so i tried and now i am just totally lost

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    This I, at least, got to compile and run:
    Code:
    /* Name : Brian Brown */
    /* Class : COSC 1415 */
    /* Assignment : Asg 7 */
    /* Date Due : Nov 25, 2002 */
    
    
    #include <stdio.h>
    #include <math.h>
    
    void PrintHeading (void);
    
    void loan (void);
    float get_amount (void);
    float get_interest (void);
    int get_term (void);
    float calculate_payment (float a, float rm, int nm);
    void printInfo (float a, float rate, float rm, int ny, int nm,
    float mp);
    void print_amortize (float a, int nm, float rm, float mp);
    
    int main ()
    {
    char ch;
    
    PrintHeading();
    loan();
    
    printf("Press any key to continue... ");
    scanf("%ch", &ch);
    
    return 0;
    
    }
    
    void loan (void)
    {
    float a;
    float rate;
    int ny;
    int nm;
    float rm;
    float mp;
    
    a = get_amount();
    rate = get_interest();
    ny = get_term();
    nm = ny * 12;
    rm = rate/nm;
    mp = calculate_payment (a, rm, nm);
    printInfo (a, rate, rm, ny, nm, mp);
    print_amortize (a, nm, rm, mp);
    }
    
    float get_amount (void)
    {
    float a;
    
    printf("Please enter amount of loan: ");
    scanf("%f", &a);
    
    return a;
    }
    
    float get_interest (void)
    {
    float rate;
    
    //scanf("%f", &rate);
    printf("Please enter an interest rate: ");
    scanf("%f", &rate);
    
    return rate;
    } /*end get_amount */
    
    int get_term (void)
    {
    int ny;
    
    //scanf("%d", &ny);
    printf("Please enter term of the loan: ");
    scanf("%d", &ny);
    
    return ny;
    }
    
    float calculate_payment (float a, float rm, int nm)
    {
    float p;
    float Q;
    float mp;
    
    p = pow((1 + rm), nm);
    Q = p/(p - 1);
    mp = a * rm *Q;
    
    return mp;
    }
    
    void printInfo (float a, float rate, float rm, int ny, int nm,
    float mp)
    {
    printf("The amount of the loan (principal): %6.2f", a);
    printf("\nInterest rate/year (percent): %4.1f", rate);
    printf("\nInterest rate/month (decimal): %5.6f", rm);
    printf("\nNumber of years: %6d", ny);
    printf("\nNumber of months: %6d", nm);
    printf("\nMonthly payment: %6.2f", mp);
    printf("\n Old Monthly Interest Principal New");
    printf("\nMonth Balance Payment Paid Paid Balance");
    }
    
    
    void print_amortize (float a, int nm, float rm, float mp)
    {
    int month;
    float OldBalance = a;
    
    for(month = 1; month <= nm; month++)
    {
    float InterestPaid = OldBalance * rm;
    float PrincipalPaid = mp - rm;
    float NewBalance = OldBalance - PrincipalPaid;
    printf("%5d %9.2f %9.2f %9.2f %9.2f\n");
    OldBalance = NewBalance;
    }
    return;
    }
    
    
    void PrintHeading (void)
    {
    printf("Name : Brian Brown\n");
    printf("Class : COSC 1415\n");
    printf("Assignment : lab 7\n");
    printf("Date Due : Nov 25,2002\n");
    printf("\n");
    }
    Now, I don't have the slightest idea about how 'happy' I am, but, never mind that part.

    Your prompts work fine. Up until the 'table' executes, you're okay, as well.

    (C programmers, feel free to jump in here, would ya?!?)

    Anyway, Belfour, let me digest this a little more. In the meantime, take what I've posted and start doing some debugging of your own. Pay attention to the 'scanf' stuff I've commented out because they hang the program. Also, your functions must re-declare your variables. They're out of scope!

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Code:
    #include <stdio.h>
    #include <math.h>
    
    void PrintHeading (void);
    
    void loan (void);
    float get_amount (void);
    float get_interest (void);
    int get_term (void);
    float calculate_payment (float a, float rm, int nm);
    void printInfo (float a, float rate, float rm, int ny, int nm,
    float mp);
    void print_amortize (float a, int nm, float rm, float mp);
    
    int main ()
    {
    PrintHeading();
    loan();
    
    return 0;
    
    }
    
    void loan (void)
    {
    float a;
    float rate;
    int ny;
    int nm;
    float rm;
    float mp;
    
    a = get_amount();
    rate = get_interest();
    ny = get_term();
    nm = ny * 12;
    rm = rate/nm;
    mp = calculate_payment (a, rm, nm);
    printInfo (a, rate, rm, ny, nm, mp);
    print_amortize (a, nm, rm, mp);
    
    }
    
    float get_amount (void)
    {
    float a;
    
    printf("Please enter amount of loan: ");
    scanf("%f", &a);
    
    return a;
    
    }
    
    float get_interest (void)
    {
    float rate;
    
    scanf("%f", &rate);
    printf("Please enter an interest rate: ");
    scanf("%f", &rate);
    
    return rate;
    
    } /*end get_amount */
    
    int get_term (void)
    {
    int ny;
    
    scanf("%d", &ny);
    printf("Please enter term of the loan: ");
    scanf("%d", &ny);
    
    return ny;
    
    }
    
    float calculate (float a, float rm, int nm)
    {
    
    float p;
    float Q;
    float mp;
    
    
    p = pow((1 + rm), nm);
    Q = p/(p - 1);
    mp = a * rm *Q;
    
    return mp;
    
    }
    
    void printInfo (float a, float rate, float rm, int ny, int nm, float mp)//notice lack of ;
    {
    
    printf("The amount of the loan (principal): %6.2f", a);
    printf("\nInterest rate/year (percent): %4.1f", rate);
    printf("\nInterest rate/month (decimal): %5.6f", rm);
    printf("\nNumber of years: %6d", ny);
    printf("\nNumber of months: %6d", nm);
    printf("\nMonthly payment: %6.2f", mp);
    printf("\n Old Monthly Interest Principal New");
    printf("\nMonth Balance Payment Paid Paid Balance");
    
    
    }
    
    
    void print_amortize (float a, int nm, float rm, float mp)
    {
    int month;
    OldBalance = a; //need to declare variable before use
    
    for(month = 1; month <= nm; month++)//notice ; instead of , before month++
    {
    InterestPaid = OldBalance * rm; //need to declare variable before use
    PrincipalPaid = mp - rm; //need to declare variable before use
    NewBalance = OldBalance - Principal; //need to declare variable before use
    
    Printf("%5d %9.2f %9.2f %9.2f %9.2f\n"); //needs to be printf, not Printf
    OldBalance = NewBalance;
    }
    
    return 0; //funtion is void, no need for return statement
    
    }
    
    
    void PrintHeading (void)
    {
    printf("Name : Brian Brown\n");
    printf("Class : COSC 1415\n");
    printf("Assignment : lab 7\n");
    printf("Date Due : Nov 25,2002\n");
    printf("\n");
    
    
    }
    pay attention to comments. I really don't know C, but that should help debug the errors.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Belfour,

    Can we talk? Let's, also, think in terms of using descriptive variable names? 'a' for 'principal' doesn't get it! (I'm pulling your leg here, but not by much!)

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    I leave the formatting of the data, for display purposes, to you (you probably know better than I do...right?). I've played with it, but that's all I've done is "play". (A little success, but...)

    Your 'print_amortize' function is giving some God-awful value in the first column. Double-check both the type and value here. The fact that the value goes negative after 'x' number of iterations suggests that you're exceeding the limits of the 'type' that's being printed. (A "flag", as it were.) Again, I'm abyssmally weak in C so I can't say what's going on, or why.

    Hopefully, one of the other folks with a stronger background in C will offer some advice.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 07-03-2009, 11:20 AM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. bcc 5.5 Declaration terminated incorrectly
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-28-2008, 04:45 PM
  4. Declaration terminated incorrectly
    By Griffin2020 in forum C Programming
    Replies: 8
    Last Post: 04-26-2002, 11:53 PM
  5. declaration terminated incorrectly
    By Clane in forum C++ Programming
    Replies: 4
    Last Post: 03-08-2002, 12:09 AM