Assert: When to and when not to.
Code:
void edit(employee * _employee)
{
assert (_employee !=NULL);
printf ("%d\n",*_employee);
string input;
int selection;
bool goodinput = false; //loop conditional, input must match conditions, else continue
while (goodinput == false)
{
cout << "What would you like to change?" << endl // prompt
<< "1. Name" << endl << "2. Payrate" << endl;
getline(cin, input); //get input
stringstream(input) >> selection; //extract selection integer
if (selection == 1)
{
cout << "Please enter a name for this employee: ";
getline(cin, _employee->name);
goodinput = true;
}
else if (selection == 2)
{
goodinput = true;
cout << "Please enter a pay rate for this employee (hourly): ";
getline(cin, _employee->payrate);
}
else
{
goodinput = false; // invalid selection - continue loop
cout << "Please enter a valid selection, 1 or 2." << endl;
}
}
}
Is this pretty much a good time to use assert? I'm putting it in places where normally I should probably have a control path for but don't yet, so in debug I know what's going on.