...

View Full Version : exit confirmation in C



hackerzlab
09-22-2009, 06:41 AM
i'm writing a code in C which ask the user his client's name, address, age, etc. once the entry is done it ask the users to enter the options to view the details of each clients.

i'm unable to figure out how people put the "are you sure u want to exit the program? Press Y for Yes, Press N for No"

could anyone help me with this.. here's some part of the codes:



remove


I wanna add that exit function so as to enable the user to quit anytime they want. please help me with this. thanx

abduraooft
09-22-2009, 08:38 AM
Something like

char c;
while(1){
printf("Menu is here\n");
printf("Press 1.Reading details of employee\n");
printf("Press 2.Sorting in increasing order of empnumber\n");
printf("Press 5.Searching details of employee by empnumber\n\n");
printf("What option u want?===== ");
scanf("%d",&k);
.......................
printf("Do you want to continue? Press Y for Yes, Press N for No \n")
c=getchar();
if(c=='N')
break;
}

Shyama_Mukherji
09-22-2009, 09:51 AM
Hope this code for a 'Yes' or 'No' option works fine:
char c;
while ( c=getchar() != 'N')
{
if ( c == 'Y')
{
printf("Menu is here\n");
printf("Press 1.Reading details of employee\n");
printf("Press 2.Sorting in increasing order of empnumber\n");
printf("Press 5.Searching details of employee by empnumber\n\n");
printf("What option u want?===== ");
scanf("%d",&k);
.......................
printf("Do you want to continue? Press Y for Yes, Press N for No \n")
}
}

hackerzlab
09-22-2009, 01:59 PM
thanx guys for the effort. really appreciate it. both the codes gave error but i got it figure it out.

thanx again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum