Hi all,
Sorry to be a nuisance, I find that I learn more from you than from my text (professor doesn't teach, respond to emails or grade assignments).
I have another payroll assignment, but less math-heavy. Everything is to be done with for, while, and do/while loops. Right now, I need to establish a range of valid entries for variables-, because the professor wants error messages returned for a series of bad entries for pay rate, hours worked, etc.
I know how to accomplish this with if/else statements (thanks to you) and now I need to learn to do it with loops. Example: employee ID should be between 1 and 100.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int empID;
int nextVariable;
cout << "Enter employee ID " << endl;
cin >> empID;
do{
cout << "Invalid entry. Please enter employee ID " << endl;
}while( empID >100 && empID <1 );
do{
cout << "Enter nextVariable " << endl;
cin >> nextVariable;
}while ( empID >=1 && empID <=100 );
system("PAUSE");
return 0;
}
|
I want this code to keep returning to ask for the employee ID if the id given is not between 1 and 100. My compiler won't let me use return==false/true to accomplish this, in a do/while statement. Suggestions appreciated, as I said, I learn more from your example codes than I do from my text.