Thread: passing value of one function into another

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    12

    passing value of one function into another

    hey i have written two functions and need to pass the value given to one function into an equation that is contained in another function.

    this is the first function that is given a value from user input:

    Code:
    double getAltitude()
    {
    double a;
    
    
    printf("\nEnter altitude (m):");
    scanf("%lf", &a);
    
    
    if (a > 9000)
    {
    printf("Invalid input! Altitude must be between 0 and 9000m");
    return getAltitude();
    }
    else if ( a < 0 )
    {
    printf("Invalid input! Altitude must be between 0 and 9000m");
    return getAltitude();
    }
    return a; 
    }
    and i need to use this value entered by the user to solve an equation inside of this function

    Code:
    double density()
    {
    double density, a ;
    density = (1.2 - 1.33*pow(10, -4)*a);
    return density; 
    }
    where the user input from the first function should be called in place of the variable (a) in the density equation.

    any help would be appreciated

    cheers

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "...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. Replies: 2
    Last Post: 10-02-2018, 09:52 AM
  2. Passing the address of a function to a function.
    By SqueezyPeas in forum C Programming
    Replies: 2
    Last Post: 09-17-2015, 07:42 AM
  3. Passing variable from function - main - function
    By ulti-killer in forum C Programming
    Replies: 2
    Last Post: 11-01-2012, 12:14 PM
  4. help with passing a pointer to a function to another function
    By csepraveenkumar in forum C Programming
    Replies: 5
    Last Post: 03-20-2011, 01:13 PM
  5. Replies: 1
    Last Post: 09-04-2007, 10:00 PM

Tags for this Thread