Jump to content
  • Advertisement
Sign in to follow this  
Mukunda

Beginning C++ Game Programming exercise question...

This topic is 4184 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!