do-while loop with condition

This is a discussion on do-while loop with condition within the C Programming forums, part of the General Programming Boards category; Hi all First post here so i just written a code for GCD What I did is enclosed the whole ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    do-while loop with condition

    Hi all

    First post here

    so i just written a code for GCD
    What I did is enclosed the whole code in a do-while loop in order to ask the user to repeat the procedure.

    Code:
     assume all variables were declared alerady 
    ......
    do
    {
    ..... code.....
    .................
    
    printf("Get GDC again (Y/N)? ");
                   scanf(" %c", &again);
    
    }while ((again== 'y') || (again== 'Y'));
    any other combination will just exit the program.
    can I add a combination that the program will terminate on pressing 'n' or 'N', and that on any other output it will ask the user if they want to try again?

    thank you all

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    can I add a combination that the program will terminate on pressing 'n' or 'N', and that on any other output it will ask the user if they want to try again?
    Assuming I understand your question, it's just a matter of reversing the test:
    Code:
    do {
        ...
    } while (tolower(again) != 'n');
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. While loop not skipping when condition isn't met
    By MNM1245 in forum C Programming
    Replies: 7
    Last Post: 11-04-2012, 04:32 PM
  2. what condition in the while loop?
    By joeman in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2010, 10:49 AM
  3. Overide for loop condition
    By erasm in forum C Programming
    Replies: 2
    Last Post: 08-11-2009, 08:08 AM
  4. need while(for(loop)) to be condition
    By thestien in forum C++ Programming
    Replies: 4
    Last Post: 10-12-2006, 08:32 AM
  5. help with loop condition
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2002, 11:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21