Using default arguments, write a function that asks the user for a number and returns that number. The function should accept a | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Using default arguments, write a function that asks the user for a number and returns that number. The function should accept a

Using default arguments, write a function that asks the user for a number and returns that number. The function should accept a string prompt from the calling code. If the caller doesn’t supply a string for the prompt, the function should use a generic prompt. Next, using function overloading, write a function that achieves the same results. here is my code, but I keep getting error .#include <iostream> #include <string> using namespace std; int askNumber(string prompt = 1); int main() { int answer = askNumber("Please enter a number: "); cout << "The number you entered is: " << answer << "\n\n"; return 0; } int askNumber(string prompt) { int num; cout << prompt; cin >> num; return num; } I know the default argument in the parameter there (string prompt = 1) is illegal. I've tried different codes, this one brings less errors than others i've tried. What am I supposed to do?

17th Oct 2019, 11:53 AM
Octopus George
Octopus George - avatar
1 Answer
0
You simply need to use int askNumber(string prompt = "generic prompt")
17th Oct 2019, 12:11 PM
Aaron Eberhardt
Aaron Eberhardt - avatar