I have a program that try's to use default parameters (arguments) as a way for a function to accept varied arguments, however, I keep getting errors:-
main.cpp: In function ‘int main()’:
main.cpp:17: error: too few arguments to function ‘void PrintLine(char, int, int)’
main.cpp:25: error: at this point in file
main.cpp: At global scope:
main.cpp:30: error: default argument for ‘char character’ has type ‘const char [2]’
Assignment_4_Question3.cpp: In function ‘int main()’:
Assignment_4_Question3.cpp:18: error: too few arguments to function ‘void PrintLine(char, int, int)’
Assignment_4_Question3.cpp:24: error: at this point in file
Why pass variables at all if you are going to set defaults to all of them
instead write two functions.. one that declares local variables as defaults and takes no parameters and one function w/SAME NAME that does take parameters?
But if you want you could try setting the default values in the prototype instead of the definition
Actually I can't use overloading; am asked to write one function that can take a variable number of arguments using default arguments! I can't use any standard library headers as well :(
Having the defaults in the prototype actually works, however, it doesn't adapt depending on the input provided; the output is always the default, even though I change the input!
Am a bit confused here! Firstly the problem is that if I used variables then I have to prompt the user to input some numbers; now if I prompt the user using "cin >> a;" for example then I am defaulting to one input variable. However, I would like the user to have the choice of just inputting 0,1,2 or 3 variables and using default arguments in the function, the appropriate calls are made. I am not allowed to use strings/arrays/library functions and IF statements within the function itself.
This is my code thus far, although I don't think am solving the problem (again cin is asking for three input variables, if I don't supply cin with three variables then the program doesn't run)
It's quite simple of you have them separate them with commas instead of spaces, then you can store them in a cstring and parse to see what they gave you. Inputting 12,34 could be taken in all at once because there are no spaces or newlines.
The issue is that his assignment is to use default parameter values, and he is NOT allowed to use function overloading.
Sorry, C++ police. He should of specified that information within his original post, not n post after the original post. Since that information was missed out, I assumed he was allowed to overload methods.