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?
Re: calling a function within a function
I don't understand what the question is...
Viggy
Re: calling a function within a function
Quote:
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.
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?
Re: calling a function within a function
Quote:
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?
See my last post, and after that you need to create a if to check if you need the print the extra info.
Re: calling a function within a function
Quote:
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();