Thread: multiplying functions

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

    Post multiplying functions

    hi i have written a code with multiple functions and i was wondering how i could multiply these functions together. a value is given to the functions from user input as seen below.

    Code:
    int main()
    {
    printf("-- Wind turbine power calculator -- \n");
    
    
    getType();
    
    
    getDiameter();
    
    
    getAltitude();
    
    
    getVelocity();
    
    
    getPerformance();
    
    
    getGenerator();
    
    
    getGearbox();
    
    
    
    
    
    
    return 0;
    }
    this is my main function in my code and i need to find this equation power = type x altitude x velocity x performance x generator x gearbox i was wondering how i could write a code that would perform this in order to calculate the power. the functions are written in this form

    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();
    }
    }
    if this is not possible and i need to write the code in a different manner please let me know or if you have a solution then cheers.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Rewrite those functions to return values. Then, in main you can store the return values in variables, then multiply them to get your final result.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by Click_here View Post
    Sorry, but a one page VERY brief tutorial does NOT equal a good book on The C Programming Language.

    This site does have a list of Programming books, but the list is in serious need of an update. Some of the books listed have more current editions.

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by rstanley View Post
    Sorry, but a one page VERY brief tutorial does NOT equal a good book on The C Programming Language.

    This site does have a list of Programming books, but the list is in serious need of an update. Some of the books listed have more current editions.
    It might be enough for the OP to move forward with...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiplying matrixes
    By Tamim Ad Dari in forum C++ Programming
    Replies: 4
    Last Post: 06-03-2013, 10:17 PM
  2. multiplying log function
    By kromagnon in forum C Programming
    Replies: 13
    Last Post: 11-03-2011, 08:53 AM
  3. multiplying to bye arrays
    By john27 in forum C Programming
    Replies: 5
    Last Post: 07-13-2011, 02:51 PM
  4. Multiplying polynomials
    By budala in forum C Programming
    Replies: 6
    Last Post: 08-19-2009, 03:19 PM
  5. Multiplying! PLEASE HELP!!!!!!!!!!!!!
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 10-23-2001, 09:12 AM

Tags for this Thread