how can i write

2 ビュー (過去 30 日間)
nil co
nil co 2015 年 12 月 27 日
コメント済み: Image Analyst 2015 年 12 月 27 日
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

採用された回答

Image Analyst
Image Analyst 2015 年 12 月 27 日
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 件のコメント
nil co
nil co 2015 年 12 月 27 日
g
Image Analyst
Image Analyst 2015 年 12 月 27 日
What is this?
Why did you post this screenshot?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by