|
-
February 21st, 2011, 03:15 PM
#1
Changing function based on a condition?
I was wondering if it's possible to have ONE function perform a different task, depending on some condition, or would I have to make separate functions? Here's my example:
Code:
int x, y, z, product;
x = getData();
y = getData();
z = getData();
int getData()
{
int num;
cout << "Please enter a number: ";
cin >> num;
return num;
}
That was an in-class exercise. BUT... can I have getData say something like "Please enter first number: " then "Please enter second number: ", etc? ... or would I need three separate functions saying three separate things? I am working on a different project, and if I can do this, it would be great! So... is there a way? I don't know enough yet to figure that out. By the way... just pointing me in the right direction is fine... I don't want to have the answer handed over - I want to learn how myself. Also, we haven't learned pointers or any of that stuff yet... just doing functions now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|