Home > atmlab > handy > yes_or_no.m

yes_or_no

PURPOSE ^

YES_OR_NO Prompts a question and only allows only 'y' or 'n' as answer.

SYNOPSIS ^

function bool = yes_or_no( s )

DESCRIPTION ^

 YES_OR_NO   Prompts a question and only allows only 'y' or 'n' as answer.

    The question string S shall only contain the question without any
    ? character. If s='Do you like money', the prompted question is:

          Do you like money [y,n]?:

 FORMAT   bool = answer_is_yes( s )

 OUT      bool   If anser is y, bool=1, else bool=0.
 IN       s      String with question.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

yes_or_no.m

SOURCE CODE ^

0001 % YES_OR_NO   Prompts a question and only allows only 'y' or 'n' as answer.
0002 %
0003 %    The question string S shall only contain the question without any
0004 %    ? character. If s='Do you like money', the prompted question is:
0005 %
0006 %          Do you like money [y,n]?:
0007 %
0008 % FORMAT   bool = answer_is_yes( s )
0009 %
0010 % OUT      bool   If anser is y, bool=1, else bool=0.
0011 % IN       s      String with question.
0012 
0013 % HISTORY: 2002-03-10  Created by Patrick Eriksson
0014 %          2003-03-05  Copied from AMI to Atmlab by PE
0015 
0016 function bool = yes_or_no( s )
0017 
0018 response = 'w';
0019 
0020 while length(response)~=1 | (response~='y' & response~='n')
0021   response = lower( input([s,' [y,n]?: '],'s') );
0022 end
0023 
0024 if response == 'y'
0025   bool = 1;
0026 else
0027   bool = 0;
0028 end
0029 
0030

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005