简体   繁体   中英

C++ Function Problem

I have gone over this back and forth and keep getting this error: 'ReadDials' : function does not take 0 arguments, can I get at least a point in the right direction?

#include <iostream>

using namespace std;

//declaring function
int ReadDials(int);

int main()
{
    //declaring each character of the phone number
    char num1, num2, num3, num4, num5, num6, num7, num8;
    bool quit = false;
    int code;

    while(quit != true || quit != true)
    ReadDials(code);
    if (code == -5)
        cout << "I love football!" << endl;
    else 
        return 0;
}

int ReadDials()
{
    //getting number from user
    cout << "Enter a phone number (Q to quit): ";
    cin >> num1;
    if (num1 == 'q' || num1 == 'Q')
    {
        code = -5;
        return code;
    }
    cin >> num2 >> num3 >> num4 >> num5 >> num6 >> num7 >> num8;
}

Actually ReadDials takes 9 arguments, so you can't call ReadDials() without passing anithing to it. then, as far as I can see, the function "karma" seems to return the number the user "dials", but it will probably fail in this intent, since parameters are passed by value, so the function changes are not propagate outside. To achieve this you will probably better passa to the function a char*, or why not reading the whole number as a string ?

You declare ReadDials to be a function with 9 arguments:

int ReadDials(char, char, char, char, char, char, char, char, int);

and then you call it providing none:

while(quit != true || quit != true)
ReadDials();

The compiler complains. Is that surprising?

readDials被声明为带有多个参数的函数,因此在不提供相应参数的情况下调用readDials是一个错误。

您必须提供参数:

const int result(ReadDials(num1, num2, num3, num4, num5, num6, num7, num8, code));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM