|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
i can't seem to exit this loop by entering -1 which is what I would like to do.
//a couple defenitions #define ERROR 1 #define OK 0 #define QUIT -1 //here's the loop in main... cout << "Employee information printed." << endl << endl << endl; int result = extpayroll.Search (); while (result > QUIT) { result = extpayroll.Search (); } //this is the class... int extEmployee::Search () { int searchIDnum= 0; cout << endl << endl; cout << "=---------------=" << endl; cout << " Search Function" << endl; cout << "=---------------=" << endl; cout << "Enter an employee ID number to search for." << endl; cout << "Enter <-1> to exit the program." << endl; cin >> searchIDnum; while (searchIDnum >= 0) { int i = 0; while (i < employee::count && searchIDnum != employee::emplist[i].empId) { i++; } if (searchIDnum == employee::emplist[i].empId) { cout << setw(5) << "EmpId" << setw(11) << "First Name" << setw(10); cout << "Last Name" << setw(13) << "Hourly Wage" << setw(14) << "Hours Worked" << setw(15) << "Weekly Salary" << setw(8) << "Status" << endl; cout << setprecision(2) << fixed << endl << setw(5) << employee::emplist[i].empId << setw(5) << employee::emplist[i].firstname << setw(13) << employee::emplist[i].lastname << setw(7) << "$" << employee::emplist[i].wage << setw(11) << employee::emplist[i].hours << setw(12) << "$" << employee::emplist[i].wsalary; if (employee::emplist[i].flag == 0) { cout << setw(10) << "boss" << endl; } else { if (employee::emplist[i].wsalary < 1000) { cout << setw(10)<< "employee" << endl; } else { cout << setw(10)<< "employee" << endl; } } return (OK); } else if (searchIDnum == QUIT) { cout << "exit route" << endl; return (QUIT); } else { cout << "sorry no listing" << endl; return (ERROR); } } return (OK); } |
|
#2
|
|||
|
|||
|
Its a long time I've done console IO, but I assume you aren't getting the sign in.
Try a loop like [ccode] int i=0; while(i>=0) { cin >> i; cout << i; } [/ccode] and see if you can input negative numbers. (Or just use the debugger). If you can, just add the rest of your code block by block and see when it breaks. |
|
#3
|
|||
|
|||
|
u have ur search function return OK irrespective of the input...u have to include this listing...
if (searchIDnum == QUIT) { cout << "exit route" << endl; return (QUIT); } else { cout << "sorry no listing" << endl; return (ERROR); } outside the while loop..or change ur pgm to return QUIT all the time... |
|
#4
|
|||
|
|||
|
aabha...you hit the nail on the head.
"u have ur search function return OK irrespective of the input... " I moved the last return (OK) statement outside one set of brackets and it worked... ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > problems exiting loop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|