Thread: Help me out understand what I need to do please?

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    38

    Help me out understand what I need to do please?

    Here is the directions I have for my assignment

    A student of the FAU Computer Science program graduates on their birthday at age X.
    They are immediately hired by a company at salary Y (after taxes). They save Z percent of their income each year in a cookie jar on top of their refrigerator. Each year, on their birthday, they add the contents of the cookie jar to their tax-deferred investment plan which returns W percent compounded annually (on their birthday).

    Write a C program which reads in the values of X, Y, Z and W from the keyboard and displays on the screen how much money they have in their investment plan on every birthday up to age 95. (When they retire to a life of yachting, race car driving, and attending those wild FAU alumni parties!). At the bottom of this, display on the screen what their age is when they become a millionaire (only count money in the investment plan, not the cookie jar).

    I'm not really understanding the W one... anyone care to help? =/

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Well an investment plan is pretty lame if it doesn't make any interest. W is going to tell you how much interest they're earning each year. If W is 5% and they have $100 in their investment plan, then they gain $5 each year from interest. What about it don't you understand? Do you just not know what interest is?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    english is not my 1st language, so I got a little bit confused I guess...

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    I dont even know what kinda coding i'm supposed to write for this project

    all I know is I gotta use loops, and at least 3 userdefined functions

  5. #5
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Describe what you want the program to do. Express it in a set of statements that could be translated into code, then convert it to code. Example:

    Get age from user into X
    Get salary from user into Y.
    Get percent saved from user into Z.
    Get compound interet percent from user into W.

    Code:
    Loop from age = X to age = 95
    {
         Calculate how many years passed since the current time.
         Apply compound interest formula based on number of years
         Output the result
    }
    For information on interest, see http://en.wikipedia.org/wiki/Interest

    Make a good attempt at coding this, and we'll help.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    This is what I have so far...
    Code:
    #include <stdio.h>
    
    int main ()
    {
        int agex;
        double salaryy;
        double savez;
        double investw;
    // we get all the information we need here
    printf ("Enter your birthday\n");
    scanf ("%f", &agex);
    printf ("Enter your salary\n");
    scanf ("%lf", &salaryy);
    printf ("What percentage of your salary would you like to put in the cookie jar?\n");
    scanf ("%lf", &savez);
    printf ("What is the interest rate?\n");
    scanf ("%lf", &investw);
    {
    
    for( int age = agex; age != 96; age++ )
    }
    }
    I keep getting an error on the for line saying
    20 'for' loop initial declaration used outside C99 mode

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    It seems likely your earlier training used the bastard C/C++ language instead of one or the other. Try
    Code:
       int age, agex;
    along with
    Code:
       for ( age = agex; age != 96; age++ )
    And don't forget to use the proper format sepcifier:
    Code:
       scanf ("%d", &agex);
    And add this before the end of main, just for "Be Kind to the OS Day":
    Code:
       return 0;
    Last edited by Dave_Sinkula; 10-11-2005 at 10:05 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    Quote Originally Posted by Dave_Sinkula
    It seems likely your earlier training used the bastard C/C++ language instead of one or the other. Try
    Code:
       int age, agex;
    along with
    Code:
       for ( age = agex; age != 96; age++ )
    And don't forget to use the proper format sepcifier:
    Code:
       scanf ("%d", &agex);
    And add this before the end of main, just for "Be Kind to the OS Day":
    Code:
       return 0;
    yeah I hadnt added the return 0 cuz i'm trying to figure out this program lol, but i will put that in the end, and thx for cataching the "%d"!

    I've changed to code to this

    Code:
    #include <stdio.h>
    
    int main ()
    {
        int agex, age;
        double salaryy;
        double savez;
        double investw;
    // we get all the information we need here
    printf ("Enter your birthday\n");
    scanf ("%d", &agex);
    printf ("Enter your salary\n");
    scanf ("%lf", &salaryy);
    printf ("What percentage of your salary would you like to put in the cookie jar?\n");
    scanf ("%lf", &savez);
    printf ("What is the interest rate?\n");
    scanf ("%lf", &investw);
    
    for( age = agex; age != 96; age++ )
    { 
    //what now? lol I guess i'll figure that part out when I wake up
    }    
    return 0;
    }
    teacher also told us to put in user defined functions, but I dont know where to put these (I need to look over and figure out how to write'm anyways)

    Your program should have at least three (3) user defined functions with the following prototypes:
    void Instruction( );
    /* this function displays instructions on how the program works
    void DisplayMillionAge( int a);
    /*this function takes the age when the user will become a millionaire. */
    int GetStartAge( );
    /*This function prompts the student for their current age and returns it*/

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Protoypes go before the function is called to tell the compiler whether you're using them correctly. The function definitions, then, can go later even after they are used (as long as the "signature" matches and things are done properly).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed