This is only a small fraction of the code I have written so far, but I am having some difficulty getting the do while loop to run the right way. Here is what I am trying to do. I want the user to input an employee's name,hourly pay, and hours worked. Say the very first time someone enter's a number instead of a name. How do I say wrong entry then repeat the loop so that it start's over from the first line ?
do
{
for(int ctr0 = 0; ctr0 <= 7; ctr0++)
{
cout << "Enter the Employee's name: ";
getline(cin, eArray[ctr0]);
cout << "Enter the hourly pay: ";
cin >> HourPy[ctr0];
cin.ignore();
}
cout << "\n";
for(int ctr1=0; ctr1 <= 7; ctr1++)
{
cout << name << eArray[ctr1] << space;
cin >> HrWkd[ctr1];
}
cout << " You enter the wrong numerical or data entry " << "\n";
cout << " I would suggest you take your time when typing " << "\n";
cout << " At this time you may enter 'Y' or a 'N'";
cin >> ans;
}
while((ans !='Y')&&(ans !='N')&&(ans !='y')&&(ans !='n'));
This means that whenever the user enters anything that is NOT [yYnN], the loop continues.
If the user enters any of y, Y, n or N, the loop terminates.
if instead while((ans !='N') && (ans !='n'));
Then the loop will continue until the user enters n or N.
if while((ans =='Y') || (ans =='y')); Then the loop continues as long as the user enters y or Y, otherwise it terminates.