how can i write

1 次查看(过去 30 天)
nil co
nil co 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 个评论
Image Analyst
Image Analyst 2015-12-27
What is this?
Why did you post this screenshot?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by