how can i write

1 visualizzazione (ultimi 30 giorni)
nil co
nil co il 27 Dic 2015
Commentato: Image Analyst il 27 Dic 2015
Write a program that prompts the user to enter an integer from 1 to 8. If the user enters a number different than specified numbers, request the user to enter again until the number entered is in range 1 to 8. The number entered by the user specifies the number of rows printed and your program should give the following output: Using array(matrix) is not allowed

Risposta accettata

Image Analyst
Image Analyst il 27 Dic 2015
Here's a snippet I've posted many times, and I've added a few lines at the bottom to get you started.
% Ask user for an integer number.
defaultValue = 45;
titleBar = 'Enter an integer value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
desiredNumbers = [................
if ismember(integerValue, desiredNumbers)..............
You could also use "if ~isempty(ismember(................." instead if you want.
  2 Commenti
nil co
nil co il 27 Dic 2015
g
Image Analyst
Image Analyst il 27 Dic 2015
What is this?
Why did you post this screenshot?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by