Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C++ (https://www.askmehelpdesk.com/forumdisplay.php?f=439)
-   -   C2660, does not take 0 arguments (https://www.askmehelpdesk.com/showthread.php?t=144541)

  • Oct 24, 2007, 03:34 PM
    Rebekah_S
    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
  • Oct 25, 2007, 06:10 AM
    asterisk_man
    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.

  • All times are GMT -7. The time now is 07:08 PM.