Thread: assigning a value to a function

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

    assigning a value to a function

    hi i have written a function outside of my main code and i was wondering how i could rewrite the function to return a value so that in my main code i can store the return value in a variable. this is the function code below

    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();
    }
    }
    
    


    cheers

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assigning pointers to array in function
    By Kirderf in forum C Programming
    Replies: 2
    Last Post: 10-11-2016, 09:04 AM
  2. Replies: 2
    Last Post: 11-03-2010, 07:00 AM
  3. function to assigning index in front
    By yangss in forum C Programming
    Replies: 7
    Last Post: 08-31-2010, 07:38 PM
  4. Replies: 9
    Last Post: 09-19-2007, 02:26 AM
  5. Assigning
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-08-2001, 06:29 PM

Tags for this Thread