|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
contribution: mylib_input_integer## Copyright of Octave (C) 1996, 1997 John W. Eaton
## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, write to the Free ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. Hello Dear Maintainers! Here is my contribution, feel free to improve it ;-) Sincerely Yours Stefan Pofahl ********************************************************************** ## -*- texinfo -*- ## @deftypefn {Function File} {} input_integer (@var{min}, @var{max}) ## Prompt integer number, min and max values optional ## ## @code{input_integer (@var{min}, @var{max})} will ask you to prompt an ## integer value, input is checked if it is a true integer number. ## ## If @var{min} and @var{max} are given as pareters and both are scalare ## values they are used as borders for the prompt. ## Output is an integer number. ## ## Author: Stefan N. Pofahl <stefan@...> ## Created: Dez. 2006, Vers.1.0(Dez.2006) ## Adapted-By: n.n. function integer_number= mylib_input_integer(min_integer, max_integer) fflush(stdout); # flush buffer to the standard output is_integer=false; outside_min_max=true; integer_number= realmin; if (nargin==2) if (isscalar(min_integer) && isscalar(max_integer))# condition1 str_prompt= ["please prompt integer number between ",... int2str(min_integer) ," and ", int2str(max_integer), ": "]; endif else min_integer= realmin;# [statementblock] max_integer= realmax; str_prompt= "please prompt integer number: "; endif while ((not(is_integer)) || outside_min_max) fflush(stdout); # flush buffer to the standard output integer_number= input (str_prompt, "s"); fflush(stdout); # flush buffer to the standard output is_digit=isdigit(integer_number); is_integer=min(is_digit); # condition1 if is_integer # condition1 integer_number= str2num(integer_number); if ((integer_number<min_integer)||(integer_number>max_integer) )# condition1 outside_min_max=true; # [statementblock] else outside_min_max=false; # [statementblock] endif else outside_min_max=true; # [else statementblock]] endif endwhile endfunction ## Copyright of Octave (C) 1996, 1997 John W. Eaton ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, write to the Free ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} input_integer (@var{min}, @var{max}) ## Prompt integer number, min and max values optional ## ## @code{input_integer (@var{min}, @var{max})} will ask you to prompt an ## integer value, input is checked if it is a true integer number. ## ## If @var{min} and @var{max} are given as pareters and both are scalare ## values they are used as borders for the prompt. ## Output is an integer number. ## ## Author: Stefan N. Pofahl <stefan@...> ## Created: Dez. 2006, Vers.1.0(Dez.2006) ## Adapted-By: n.n. function integer_number= mylib_input_integer(min_integer, max_integer) fflush(stdout); # flush buffer to the standard output is_integer=false; outside_min_max=true; integer_number= realmin; if (nargin==2) if (isscalar(min_integer) && isscalar(max_integer))# condition1 str_prompt= ["please prompt integer number between ",... int2str(min_integer) ," and ", int2str(max_integer), ": "]; endif else min_integer= realmin;# [statementblock] max_integer= realmax; str_prompt= "please prompt integer number: "; endif while ((not(is_integer)) || outside_min_max) fflush(stdout); # flush buffer to the standard output integer_number= input (str_prompt, "s"); fflush(stdout); # flush buffer to the standard output is_digit=isdigit(integer_number); is_integer=min(is_digit); # condition1 if is_integer # condition1 integer_number= str2num(integer_number); if ((integer_number<min_integer)||(integer_number>max_integer) )# condition1 outside_min_max=true; # [statementblock] else outside_min_max=false; # [statementblock] endif else outside_min_max=true; # [else statementblock]] endif endwhile endfunction _______________________________________________ Octave-sources mailing list Octave-sources@... https://www.cae.wisc.edu/mailman/listinfo/octave-sources |
| Free Forum Powered by Nabble | Forum Help |