Ask Experts Questions for FREE Help !
Ask
    Rebekah_S's Avatar
    Rebekah_S Posts: 3, Reputation: 1
    New Member
     
    #1

    Oct 24, 2007, 03:34 PM
    C2660, does not take 0 arguments
    I have read about this error message and understand that there is something that I should put between the () of the calcAvg(), but I can't figure out what! I thought it would be 'number', but that doesn't work... PLEASE HELP!
    I bold-ed the calcAvg function




    //Ch9Ex3and4.cpp - accepts an four integers, calculate the average and returns the result. Also includes exercise 4 by listing the function prototype for the calcAverage function.
    //Created/revised by Rebekah Sapp on 10/21/07


    #include <iostream>
    #include <iomanip>

    using std::cout;
    using std::cin;
    using std::endl;
    using std::setprecision;
    using std::ios;
    using std::setiosflags;

    //function prototype
    double getInput();
    double calcAvg(double, double, double, double);

    int main()
    {
    //declare variables
    double number = 0.0;
    double div = 0.0;
    double calcAv = 0.0;

    //enter input item
    number = getInput();
    calcAv = calcAvg();



    //display output item
    cout << setiosflags(ios::fixed) << setprecision(0);
    cout << "The average =: " << calcAvg << endl;

    return 0;

    } //end of main function
    //*********function definitions**********
    double getInput()
    {
    double inputNum1 = 0.0;
    double inputNum2 = 0.0;
    double inputNum3 = 0.0;
    double inputNum4 = 0.0;

    cout << "Enter first number to calculate average: ";
    cin >> inputNum1;
    cout << "Enter second number to calculate average: ";
    cin >> inputNum2;
    cout << "Enter third number to calculate average: ";
    cin >> inputNum3;
    cout << "Enter fourth number to calculate average: ";
    cin >> inputNum4;

    return inputNum1;
    return inputNum2;
    return inputNum3;
    return inputNum4;

    } //end of getInput function
    double calcAvg(double in1, double in2, double in3, double in4)
    {
    double div = 0.0;
    double calcAv = 0.0;
    calcAv = (in1 + in2 + in3 + in4)/div;
    return calcAv;
    } //end of calcAvg function
    asterisk_man's Avatar
    asterisk_man Posts: 476, Reputation: 32
    Full Member
     
    #2

    Oct 25, 2007, 06:10 AM
    Ok. Your problem is a basic lack of understanding about how functions work. If you look at the code you've provided you can see that the function calcAvg is declared at the top as the following:
    double calcAvg(double, double, double, double);

    This line is telling the program that somewhere below the function calcAvg will be defined but for the purpose of syntax checking it should know that calcAvg returns a piece of data which is of type double and requires 4 pieces of data which are all of type double.
    In your code you attempt to call the function calcAvg like this:
    calcAv = calcAvg();

    You are making use of the double that calcAvg() will return by assigning it to the variable calcAv but you are not providing any of the 4 required doubles that are inputs to the function. So this is your first mistake. You should be using a line that looks more like:
    calcAv=calcAvg(num1, num2, num3, num4);

    The second problem that is immediately obvious to me is the contents of your function getInput(). I don't think you understand what the return statement does. A function can only return one value. In this case you have specified that it will return a double. When the function executes the line "return inputNum1;" it will exit the function and return that one value, inputNum1. The other three returns will never be executed.

    Please try to rework your program taking this things into account and let us know if you need any more assistance.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Analyzing Arguments [ 2 Answers ]

When you are building an argument for an issue that is significant to you, do you think it is more important to be valid or sound?

I can't handle arguments! [ 5 Answers ]

If my boyfriend and I have a heated discussion, and I hear his booming voice starting to grow, the first thing I do is look for the exit and RUN. I go to great lengths to avoid arguing, and sometimes walk on eggshells or just agree with him. I have even lied about petty things to prevent...

The Rules: Arguments/Discussions with your spouse/partner [ 7 Answers ]

This was in this month's issue of Envoy Magazine... couldn't resist sharing it. I am confident that if both parties of a relationship can agree with these "rules" then it's a huge step toward a successful relationship... T H E__R U L E S By Kris and Marty Franklin 1. We are on the same...

Arguments [ 3 Answers ]

I have been in a relationship with my boyfreind for 3 and a half months, and lately I have been starting loads of unnesasary arguments. He puts up with it, but I'm worried that he will get bored of me keep starting them. I really love him and he loves me and I don't want this relationship to end. I...

Descartes Arguments for Skepticism [ 1 Answers ]

What are are Descartes arguments for Skepticism? What does Descartes believe exists despite those arguments. Thank you so much, any help is much appreciated!


View more questions Search