フィルターのクリア

How to write a script to display an input of 10 times?

1 回表示 (過去 30 日間)
Kong
Kong 2013 年 11 月 13 日
コメント済み: Muhammadjawad 2022 年 12 月 5 日
Write a script to ask the user to input an integer number between 0 and 255, and output the number to the screen between the characters '<' and '>'. This input and display operation should be repeated 10 for 10 times. After the 10th iteration the script should save all the input numbers to a text file in a human readable form.
Develop a user function to do the following check for each number entered: If the number entered is bigger than 255, the script should print a message " error: value too big." to the screen. If a negative number is entered, no matter what is the exact number, the script should convert it to -1.

回答 (1 件)

Ibrahim Mohammed Wajid
Ibrahim Mohammed Wajid 2022 年 7 月 4 日
編集済み: Ibrahim Mohammed Wajid 2022 年 7 月 4 日
function numberCheck(n)
if n > 255
disp("error: value too big.");
else
if n < 0
n = -1;
else
disp("<"+n+">");
n = input('enter a number between 0 and 255');
numberCheck(n);
end
end
end
n = input('enter a number between 0 and 255');
numberCheck(n);
  1 件のコメント
Muhammadjawad
Muhammadjawad 2022 年 12 月 5 日
How do you wrie for ' After the 10th iteration the script should save all the input numbers to a text file in a human readable form.'

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

カテゴリ

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