CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2011
    Posts
    3

    Exclamation Function calling and passing problems

    I have a few functions. Function A will get input from the user as will function B. Function C is to use data from functions A and B and calculate a value. I am getting compiling errors:

    homework5.cpp: In function ‘int main()’:
    homework5.cpp:13: error: too few arguments to function ‘float burninations(float, float)’
    homework5.cpp:22: error: at this point in file

    This is my code....:

    #include<iostream>
    using namespace std;

    float get_anger_level();

    float get_arm_diameter();

    float burninations(float anger_level, float arm_diameter);

    int main()
    {
    float level = 0;
    float diameter = 0;
    float anger_level, arm_diameter;

    return 0;
    }


    float get_anger_level() // "FUNCTION A"
    {
    float anger_level;

    cout << "\nEnter Trogdor's anger level: " << endl;
    cin >> anger_level;
    return anger_level;
    }

    float get_arm_diameter() // "FUNCTION B"
    {
    float arm_diameter;
    cout << "\nEnter the diameter of Trogdor's beefy arm: " << endl;
    cin >> arm_diameter;
    return arm_diameter;
    }

    float burninantions(float anger_level, float arm_diameter) // "FUNCTION C"
    {
    get_anger_level();
    get_arm_diameter();
    float burnats = 0;



    const int CONSUMATEVS = 17;
    int burningPeasants = 40;
    burnats = (anger_level * (1+1/static_cast<float>(CONSUMATEVS)) + burningPeasants/static_cast<float>(CONSUMATEVS) + arm_diameter);
    cout << burnats << endl;

    return burnats;
    }

  2. #2
    Join Date
    Aug 2008
    Posts
    902

    Re: Function calling and passing problems

    You should edit your post and use code tags. They are a standard BBcode tag.

    1. Function C as you have labeled it takes two floating point numbers, but you don't use them for anything.

    2. You call Function A and B from C but you aren't storing the return value, so this is pointless.

    3. You don't have anything in main, so your program won't do anything at all.

  3. #3
    Join Date
    Feb 2011
    Posts
    3

    Re: Function calling and passing problems

    Sorry, I am new to the forums, haven't figured out how to post code yet.

    What should I have in my main()
    would it be burninations(level, diameter)

    "You call Function A and B from C but you aren't storing the return value, so this is pointless."
    Could you explain a little more. Functions are obviously very hard for me to grasp.

    I really appreciate all help and answers.

  4. #4
    Join Date
    Aug 2008
    Posts
    902

    Re: Function calling and passing problems

    I think you should decide exactly what it is you want to accomplish, because this code looks as if you are not sure what you want it to do.

    Could you explain a little more.
    Function A and B return a float value, but your code in function C is simply calling them and not storing the return value, which doesn't accomplish anything.

  5. #5
    Join Date
    Feb 2011
    Posts
    3

    Re: Function calling and passing problems

    What I want function C to do is use the anger_level (Function A) and arm_diameter (Function B) values that were user input, and do some math with them. I want the math that is done to be stored as burnats and output this to the user.

    I don't doubt that this is the most confusing code, and I really don't have much idea of what I'm doing when it comes to calling and passing functions. I learn best by example, but the examples are too hard to follow.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured