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
is declared as a function taking several parameters, so calling it without providing the corresponding arguments is an error.
you must provide the arguments:
const int result(ReadDials(num1, num2, num3, num4, num5, num6, num7, num8, code));
精彩评论