Thread: Future Value Functions

  1. #1
    Registered User
    Join Date
    Jun 2014

    Future Value Functions

    I am having a horrible time getting my functions to communicate with each other. Please if someone could assist, I am not looking for hand-outs but am a beginner banging my head on the wall and Ritchie's C book.

    Description: This program calculates what a current amount will be worth in a future year based on yearly compounded interest earned.

    Input: User enters starting amount, interest rate, number of years, and the starting year.

    Output: Program calculates year 2019 balance, interest earned, and total percent gained.

        1. Print COP2220 line.
        2. Prompt user for starting amount.
        3. Read starting line.
        4. Prompt user for interest rate.
        5. Read interest rate.
        6. Prompt user for number of years.
        7. Read number of years.
        8. Prompt user for starting year.
        9. Read starting year.
        10. Validate input data.
        11. Check data.
        12. Print error messages.
        13. If statement errors end program.
        14. Do calculations.
            -Calculate future year.
            -Calculate future value.
            -Calculate interest earned.
            -Calculate total percent gained.
        15. Print results.
        16. Exit program.

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    //Function Declarations
    float CollectUserInputs();
    int main()
        printf("COP2220-51014 Project 2: Andrew Ossi\n\n");
        return 0;
    float CollectUserInputs()
        float startamt;
        float interestrate;
        int years;
        int startyear;
        int error;
        printf("\nEnter a Starting amount (dollars and cents): ");
        scanf("%f", &startamt);
        printf("Enter an Interest rate (ex. 2.5 for 2.5%):   ");
        scanf("%f", &interestrate);
        printf("Enter the Number of years (integer number):  ");
        scanf("%d", &years);
        printf("Enter the Starting year (four digits):       ");
        scanf("%d", &startyear);
        //validate the user inputs. if there is any kind of error, exit the program, else continue.
        error = 0;
        if (startamt <= 0){
            printf("Starting amount must be at least one cent.\n");
            error = 1;
        if (interestrate <=0){
            printf("Interest rate must be at least .1%.\n");
            error = 1;
        if (years <=0){
            printf("Number of years must be at least 1.\n");
            error = 1;
        if (startyear < 999 || startyear > 9999){
            printf("Year must be four digits\n");
            error = 1;
        //if there are errors, end the program.
        if (error == 1){
            return 0;
        else if (error == 0){
            return startamt;
            return interestrate;
            return years;
            return startyear;
        Calculate the Future Year from keyboard input and return it.
    void downFun (int startyear, int years);
    //Local Definitions
        int years;
        int startyear;
        int FY;
      *FY = startyear - years;
            return 0;
    }       downFun

  2. #2
    Registered User
    Join Date
    May 2010
    Also posted here.


  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008

    Dammit Jim, I'm a programmer, not an administrator.

    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  4. #4
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Quote Originally Posted by andyouf View Post
        else if (error == 0){
            return startamt;
            return interestrate;
            return years;
            return startyear;

    She's return'in fer all she's worth capt'n, she can no take anymore!

  5. #5
    Registered User
    Join Date
    May 2009
    Hint: You need to use pointers to have multiple values external to the function affected in the calling the function.
    If pointers not yet covered, then struct command will likely be needed, instead.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The future
    By the dead tree in forum A Brief History of
    Replies: 1
    Last Post: 02-03-2006, 11:25 AM
  2. This is the Future
    By loopshot in forum Game Programming
    Replies: 12
    Last Post: 05-21-2005, 12:13 AM
  3. The future of C++
    By tinytroon in forum Tech Board
    Replies: 3
    Last Post: 10-17-2003, 10:40 AM
  4. The Future is Here!!
    By Cheeze-It in forum A Brief History of
    Replies: 16
    Last Post: 02-17-2003, 12:09 PM
  5. Future of C++
    By CompiledMonkey in forum C++ Programming
    Replies: 9
    Last Post: 08-03-2002, 10:32 PM