C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 22nd, 2002, 01:00 AM
skaminoff skaminoff is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 0 skaminoff User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question problems exiting loop

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);
}

Reply With Quote
  #2  
Old April 23rd, 2002, 07:04 AM
WoR WoR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 23 WoR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old April 23rd, 2002, 02:32 PM
aabha aabha is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: India
Posts: 7 aabha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to aabha
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...

Reply With Quote
  #4  
Old April 23rd, 2002, 09:22 PM
skaminoff skaminoff is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 0 skaminoff User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > problems exiting loop


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT