Thread: Urgent Help...having problem with code

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    23

    Post Urgent Help...having problem with code

    this is an assignment I'm working on, and it is unfinished...so i'm stuck ... can you guys help please?
    Code:
    Write a C program that calculates the final value of an investment made in a TSX Market Linked GIC.  
    
    Specification 
    
    The return on this type of GIC (Guaranteed Investment Certificate) is based on the initial investment, the number of years (1, 2 or 3), a minimum return rate, a maximum return rate, a participation rate, the values of the TSX (Toronto Stock Exchange) index at specified intervals during the years, and the type of averaging of these values. The final investment value can only be calculated once all the TSX values are known. If averaging is not used the TSX rate is determined from the opening and closing values only. If averaging is used the TSX rate is determined by calculating the TSX average at 6 monthly intervals, then is based on this average relative to the opening value. The TSX rate is then multiplied by the participation rate. If this new rate is below the minimum rate, then the minimum rate is used, and if it is above the maximum rate, then the maximum rate is used.  Rates are printed to 2 decimal places, and the final investment is rounded down, and formatted using commas.
    
    Only round down for the final investment. If the TSX rate is negative do not print the line for rate adjusted for participation. Assume that the final investment is less than one million dollars. (Hint: if you need to print leading zeros in a number, use the %0m.n format: example – the format specifier %06.2f prints 4.56 as 004.56)
    
    Example 1: See below; averaging is not used, so TSX rate = (107-100)/100 = 7%. After using a participation rate of 80%, get 5.6% (which is between min & max rates). 
    
    Example 2: See below; averaging is used over 5 values to get a rate of 68% which equals 54.4% due to participation. This is more than the max rate, so the max rate is used.
    
    The GIC calculator must use the following layout exactly.
    
    +------------------------------------+
    |  TSX MARKET LINKED GIC CALCULATOR  |
    +------------------------------------+
    
    Enter initial investment            : 1000.00
    Enter number of years [1,2,3]       : 3
    Enter minimum and maximum rates [%] : 1 20          
    Enter participation rate [%]        : 80
    Enter if averaging used [1=yes,0=no]: 0
    Enter open and close values         : 100 107
    
    TSX rate . . . . . . . . . . . . . .  7.00%
    Rate adjusted for participation  . .  5.60%
    
    Final investment . . . . . . . . . . $ 1,056.00
    
    +------------------------------------+
    |  TSX MARKET LINKED GIC CALCULATOR  |
    +------------------------------------+
    
    Enter initial investment            : 2000.00
    Enter number of years [1,2,3]       : 2
    Enter minimum and maximum rates [%] : 1 20          
    Enter participation rate [%]        : 80
    Enter if averaging used [1=yes,0=no]: 1
    Enter 5 TSX values                  : 200 190 320 430 540
    
    TSX rate . . . . . . . . . . . . . .  68.00%
    Rate adjusted for participation  . .  54.40%
    Maximum rate is applicable . . . . .  20.00%
    
    Final investment . . . . . . . . . . $ 2,040.00
    i wrote something like

    Code:
    #include <stdio.h>
    int main (void)
    {
    int  years, minimum, maximum, partrate, x, open, close, tsxvalue;
    float investment, tsxrate, y, finalinvestment, maxrate, minrate;
    printf("+------------------------------------+\n");
    printf("|  TSX MARKET LINKED GIC CALCULATOR  |\n");
    printf("+------------------------------------+\n");
    
    printf("Enter initial investment            :  ");
    scanf("%.21f", &investment);
    printf("\n");
    printf("Enter number of years [1,2,3]       :  ");
    scanf("%d", &years);
    printf("\n");
    printf("Enter minimum and maximum rates [%] :  ");
    scanf("%d %d", &minimum, &maximum);
    printf("\n");
    printf("Enter participation rate [%]        :  ");
    scanf("%d", &partrate);
    printf("\n");
    printf("Enter if averaging used [1=yes,0=no]:  ");
    scanf("%d", &x);
    printf("\n");
    if (x=0)
    {
    printf("Enter open and close values         :  ");
    scanf("%d %d", &open, &close);
    printf("\n");
    printf("\n");
    tsxrate = (close - open)/100;
    printf("TSX rate . . . . . . . . . . . . . .  %.21f", tsxrate);
    printf("\n");
    y = tsxrate * ((float)partrate/100);
    printf("Rate adjusted for participation  . .  %.21f", y);
    printf("\n");
    printf("\n");
    finalinvestment = (y * 100) + investment;
    printf("Final investment . . . . . . . . . . $%.21f", finalinvestment);
    }
    if (x=1)
    {
    printf("Enter 5 TSX values                  :  ");
    scanf("%d %d %d %d %d", tsxvalue, tsxvalue, tsxvalue, tsxvalue, tsxvalue);
    printf("\n");
    // i don't know what the exact calculation should be here now to get the rest....so I'm stuck here

  2. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    23
    btw is there anything wrong with the programming?

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Add the hard line breaks (newlines), to the first page. Almost impossible to read it without them. The forum won't wrap the lines, since it's code.

    You have test data included in that top page you posted. Use it, and see if your program gives you the right answers.

    If you get the right answers and display, keep testing it with other data that you can verify the correct answers to.

    If you get the wrong answer, tell us what input gave you the wrong answer, and any hints about what you did to fix it. There's a real time problem when someone says "it doesn't work" or "check it for me". We just don't have the time or the interest, to do all that.

    We *help* you.

    We may note bugs we spot while helping you with other C problems, but we will NOT test your code for accuracy or completeness.

    Your program, so it's your test to do.
    Last edited by Adak; 02-20-2013 at 04:44 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent help please with C code
    By Clement Museka in forum C Programming
    Replies: 5
    Last Post: 06-15-2012, 03:50 AM
  2. could you help with me C code?thanks,a little urgent.
    By hth373737 in forum C Programming
    Replies: 50
    Last Post: 11-24-2008, 07:12 AM
  3. Urgent help in code...
    By alvifarooq in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2004, 07:40 AM
  4. Urgent: c code to explore zip/war/ear/jar files
    By chinnu in forum C Programming
    Replies: 1
    Last Post: 09-02-2003, 03:09 AM
  5. P4 Fan problem: Urgent
    By RoD in forum Tech Board
    Replies: 5
    Last Post: 01-15-2003, 12:12 PM