Thread: Help starting a C program with functions

  1. #1
    Registered User
    Join Date
    Oct 2002

    Exclamation Help starting a C program with functions

    I have a problem that has to be an interactive programs that accepts values for loan amount, yearly interest rate, and monthly payment amount from the terminal and then computes and displays on the monitor screen a loan repayment table. I have no idea how to start. I have to use at least one function but I'm not sure what needs to be a function or how many I need. Or how do I make a table that computes and displays the
    loan table? Do I have to come up with a function? I don't want you to do it for me but instead kinda walk me through what I should do.

    Here's the program's sample output:

    Problem Statement: Develop an interactive program that accepts values for loan amount, yearly interest rate, and monthly payment amount from the terminal and then computes and displays on the monitor screen a loan repayment table. Implementation Details:
    Monthly interest is computed on the beginning balance as
    (beginning balance) * (interest rate)/12

    Principal is obtained by subtracting monthly interest from monthly payment.

    Ending balance is beginning balance minus principal paid.

    The beginning balance for a month is the same as the ending balance for the previous month.

    When the beginning balance for a month becomes less than or equal to the monthly payment amount, no interest is charged and the monthly payment is considered as the principal amount. In this case the monthly payment will be the final payment on the loan.

    If the entered value for monthly payment is less than the computed monthly interest, the loan will never be repaid. Therefore, your program should print a message telling the user that the monthly payment is too small and asking the user to enter a larger value.

    Output Example: Your program execution should have the same layout.
    Enter loan amount: 10000
    Enter yearly interest rate: 0.1790
    Enter monthly payment: 30.00
    ***> Monthly payment is too small.
    Enter monthly payment: 1000.00

    Beginning Balance Payment Interest Principal Ending Balance
    -------------------------- ----------- ------------- ------------ - --------------------
    10000.00 1000.00 149.17 850.83 9149.16
    9149.16 1000.00 136.47 863.52 8258.64
    897.21 897.21 0.00 897.21 0.00 -

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    You could have anything be your function. What would make the most sense in this case would be your calculations.

  3. #3
    CS Author and Instructor
    Join Date
    Sep 2002
    You now have a good start. Now show us some code that you have written and we will help with problems. Remember the rules however.
    Mr. C: Author and Instructor

  4. #4
    Registered User
    Join Date
    Oct 2002

    Exclamation Source code that I've written

    I still don't know much about how to incorporate functions. I look in my textbook and at my class notes but still no progress. Here's what I have with functions or parameters. It's not quite finished but maybe you can help me critique what I have thus far. The program I have to write is on my first post.

    #include <stdio.h>
    int main (void)
    int amount, yrinterest, monthly;
    float beginningbalance, principal, newamount, interest, payment;
    printf ("Enter loan amount : ");
    scanf ("%d", &amount);
    printf ("Enter yearly interest rate: ");
    scanf ("%d", &yrinterest);
    monthly = yrinterest/ 12;
    yrinterest = amount * monthly;
    printf ("Enter monthly payment: ");
    scanf ("%d", &monthly);
    If yrinterest >= monthly
    printf ("Monthly payment is too small.");
    scanf ("%d", &monthly);
    printf ("Enter monthly payment:");
    Printf("Loan Repayment Table");
    While (beginningbalance > payment) {
    Principal = Payment - Interest;
    Newamt = Amount - Principal;
    Printf ("Beginning Balance \t%f", beginningbalance);
    Printf ("Payment \t%f", amount);
    Printf ("Interest \t %f", interest);
    Printf ("Principal \t %f", principal);
    Printf ("Ending Balance \t %f", newamt);
    beginningbalance=beginningbalance +1;
    Payment = amount + interest;
    Interest = amount * monthly;
    return 0;
    [EDIT]For what it's worth... code tags added by Hammer.

  5. #5
    Registered User
    Join Date
    Oct 2002

    Exclamation May I have an example

    Would someone please show/give me an example of how to start the functions and parameters from the code I already have?

    Thanks so much.

  6. #6
    Registered User
    Join Date
    Oct 2002

    Exclamation still don't understand

    I still don't understand. Can someone help me?

  7. #7
    Casual Visitor
    Join Date
    Oct 2001
    I'm on the lowest rung as far as coders go, but I believe sometimes it's better to see than to read.

    #include <stdio.h>
    int returnSum(int, int); 
    // function prototype that returns the sum of two integers.
    int main(void)
        int num1, num2, result;
        printf("Enter num1: ");
        scanf("%d", &num1);
        printf("Enter num2: ");
        scanf("%d", &num2);
        result = returnSum(num1, num2);
        // function call.  This case to add the two numbers
       printf("\nThe result is %d", result);
       return 0;
    int returnSum(int x, int y)
        return x + y;
            this is the function definition.  You place what you want your
           function to do in here.  The type of function depends on
           what is returned or if anything can be returned.  For example
           use void somefunct(char, int, float) if you need to use
           all of those variables since you can't return three data types
           at once. */

    [typo] arrgg [/typo]

    Oh, I like that void main bomb Salem. Nice touch :P
    Last edited by ronin; 10-12-2002 at 02:48 PM.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Use windows API functions in a GTK+ program?
    By Jake.c in forum Windows Programming
    Replies: 19
    Last Post: 01-23-2009, 06:40 AM
  2. Need some help with a beginner functions program!
    By nelledawg in forum C Programming
    Replies: 5
    Last Post: 03-03-2008, 07:05 AM
  3. Starting a new program
    By histevenk in forum C++ Programming
    Replies: 28
    Last Post: 10-15-2007, 04:11 PM
  4. Replies: 10
    Last Post: 02-17-2005, 09:27 PM
  5. Starting the program
    By vasanth in forum C++ Programming
    Replies: 2
    Last Post: 02-28-2002, 04:51 AM