default arguments & overloading functions

Stuck once again. For those who read my last post, I want to also state that the class I am taking is held over I-TV and I am the only one at my campus taking this class.
Anyhow, I will list the instructions to my exercise and what I have done thus far (however embarassing it is).

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.

I am having a difficult time translating these instruction to english that my brain can understand. I can create a function that asks for a number and returns that number. I can make that function accept a string argument (I don't know if 'prompt' is the same as argument). I can make the function use a default argument if a string argument is not supplied. I return a value from the function to main and display it. With my current understanding of the instruction, I have no clue how function overloading can achieve the same result, because that would suggest there are 2 possible types of arguments that could be available to the function and I don't understand how that can be.

Somehow I don't think the following code is really what the instructions are after.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 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.

#include <iostream>
#include <string>

using namespace std;

string askNumber(string prompt="Please enter a number: ");

int main()
{


    string number = askNumber();
    cout << "Here is your number: " << number << endl;
    std::system("Pause");
    
    return 0;
}

string askNumber(string prompt)
{
    string number;
    cout << prompt ;
    cin >> number;
    return number;
}


I chose string over int because I didn't know how to make "five" work if the user spelled the number instead of entering the actual number. Somehow I think that this has something to do with the true nature of my problem.

Many thanks for someone that can help me understand the instructions, or the answer...I hate sitting alone in a classroom, watching a TV, and talking into a mircophone to ask these questions.
I think perhaps they are trying to ask you to create a function that doesn't have a default prompt parameter, but that will still output a default prompt if one isn't given...although, I don't know how you would do that by overloading, because if you did, it wouldn't be able to tell which function to use.
Your respnse is pretty much what I expected. I have emailed my instructor and basically asked him the same questions. I was hoping to figure it out and possibly be the only one...hehe.

In response to "perhaps they are trying to ask you to create a function that doesn't have a default prompt parameter" .... The chapter in the book from which this exercise came from talked about default arguments in one section and overloading in another. My thoughts shadow your on this problem, I was just hoping it was me.

Thank you for taking the time to respond :)
No problem.
Topic archived. No new replies allowed.