Sign in to follow this  
Mukunda

Beginning C++ Game Programming exercise question...

Recommended Posts

So I've just gotten started properly in programming now, after playing around with it lightly for far too long and not really learning anything. I'm currently at the end of chapter 5 (of Beginning C++ game programming), and stuck on the last exercise..
Quote:
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.
Now the code I've written so far is below... But I don't see how, or even what the point would be in rewriting this to allow it to be done with function overloading... Have I stupidly misunderstood the exercise? If so, could someone explain it a bit more clearly. Thank you. #include <iostream> #include <string> using namespace std; int number(string stringInput = "Please enter a number: "); int main() { int firstNum, secondNum; firstNum = number(); cout << firstNum << endl; secondNum = number("Please put your here here -> "); cout << secondNum << endl; return 0; } int number(string stringInput) { int value; cout << stringInput; cin >> value; return value; } [Edited by - Mukunda on April 9, 2007 9:09:21 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this