function to prompt user to continue entering data or not

This is a discussion on function to prompt user to continue entering data or not within the C++ Programming forums, part of the General Programming Boards category; how would i begin writing a function that prompts the user to 'Continue entering data (Y/N)? ' it's supposed to ...

  1. #1
    Unregistered
    Guest

    Smile function to prompt user to continue entering data or not

    how would i begin writing a function that prompts the user to 'Continue entering data (Y/N)? ' it's supposed to keep asking the user until they enter one of the following characters: 'Y', 'y', 'N', or 'n'. my professor suggested a function like bool want_to_continue but i don't understand how it works. thanks. Mark.

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    Do you mean ask 'Continue entering data(Y/N)?' over and over or just stay with the same question on the same line until a correct entry is recieved?

  3. #3
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Code:
    #include <iostream>
    
    using std::cout;
    using std::cin;
    
    bool ContinueYN();   // Prototype
    
    int main()
    {
       bool data;
    
       data = ContinueYN();
    
       if(data)
          cout << "Good job: YES";
       else
          cout << "OK: NO";
    
       return 0;
    
    }
    
    bool ContinueYN()
    {
        char c = ' ';
    
       while( c != 'y' || c != 'Y' || c != 'n' || c != 'N' )
       {
          cout << "Continue? (Y/N): ";	
          cin.get(c);                           // Get character from user
          cin.ignore(1, '\n');	// Skip newline
    
          if( c == 'y' || c == 'Y' )
             return true;
          else if( c == 'n' || c == 'N' )
             return false;
       }
    
    	return false;	// Will not happen, but is more aesthetically correct
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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