Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts

    exit confirmation in C

    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:

    Code:
    remove
    I wanna add that exit function so as to enable the user to quit anytime they want. please help me with this. thanx
    Last edited by hackerzlab; 09-22-2009 at 01:59 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Something like
    Code:
    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;
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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")
    }
    }

  • #4
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts
    thanx guys for the effort. really appreciate it. both the codes gave error but i got it figure it out.

    thanx again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •