-
December 10th, 2009, 04:01 PM
#1
calling a function within a function
Hello all i am currently working on an assignment and I am almost done with it. I'm having a bit of a hard time understanding the calling of a function within a function.
Here is some background to the program. It has generated randomly the phone number, age, credit card number, and has giving each employee a 1 (for secure) or 0 (for unsecured). I bascally have two functions print_secure and print_all. If the information is not secure it will display everything and if it is, it will display certain items.
Here is what I have so far.
Code:
void CustomerData::print_all()
{
int empNo;
cout << "Please enter the Employee Number: ";
cin >> empNo;
if (0 > empNo || empNo > 49) // checks to make sure that user entered value is within the limit [0 .. 49]
{
cout << "The Employee Number entered is out of bound. Please try again.\n";
return;
}
//Employee details are printed below
cout << "\nEmployee details\n";
cout << "----------------\n";
cout << "Employee Number: " << employees[empNo].empNo << "\n";
cout << "Employee Security Preference: " << employees[empNo].security_preference << "\n";
cout << "Age: " << employees[empNo].empAge << "\n";
cout << "Phone Number: " << employees[empNo].empphone << "\n";
cout << "Credit Card Number: " << employees[empNo].empCCNo << "\n";
cout << "\n\n";
}
/*void CustomerData::print_secure()
{
//Employee details are printed below
cout << "\nEmployee details\n";
cout << "----------------\n";
cout << "Employee Number: " << employees[empNo].empNo << "\n";
cout << "Employee Security Preference: " << employees[empNo].security_preference << "\n";
cout << "Employee Age: " << employees[empNo].empAge << "\n";
cout << "\n\n";
}*/
Since I don't want a classmate taking my code I only posted what I think is the main part I need help with.
I was thing of putting an if statement in void CustomerData:: print_all() to reference void CustomerData:: print_secure() but I don't have a clue as how to reference it. Could someone offer some advise?
Last edited by Fezzy; December 10th, 2009 at 04:03 PM.
-
December 10th, 2009, 04:48 PM
#2
Re: calling a function within a function
I don't understand what the question is...
Viggy
-
December 10th, 2009, 04:54 PM
#3
Re: calling a function within a function
Originally Posted by MrViggy
I don't understand what the question is...
Viggy
He is asking us how he should remove a few cout-lines and call print_secure instead because they actually print the same.
-
December 10th, 2009, 04:54 PM
#4
Re: calling a function within a function
Sorry mate.
I want to create an if statement in the print_all function that says if "security_preference" has a 1 then us the "void CustomerData:: print_secure()" function as the output. How can I go about this?
Last edited by Fezzy; December 10th, 2009 at 04:57 PM.
-
December 10th, 2009, 04:57 PM
#5
Re: calling a function within a function
Originally Posted by Fezzy
Sorry mate.
I want to create an if statement in the print_all function that says if "security_preference" has a 1 then us the "void CustomerData: rint_secure()" function as the output. How can I go about this?
See my last post, and after that you need to create a if to check if you need the print the extra info.
-
December 12th, 2009, 02:48 AM
#6
Re: calling a function within a function
Originally Posted by Fezzy
Sorry mate.
I want to create an if statement in the print_all function that says if "security_preference" has a 1 then us the "void CustomerData:: print_secure()" function as the output. How can I go about this?
Why cant you think of doing that condition check in the place where you intend to call print_secure() or print_all()?
i mean like,
Code:
CustomerData cd;
if( security_preference == 1 )
cd.print_secure();
else
cd.print_all();
"I studied everything but never topped. Today, toppers of the world's best universities are my employees"
-William Henry Gates (Bill Gates)
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
|