repeat function and calculation

8 ビュー (過去 30 日間)
matt noman
matt noman 2020 年 3 月 8 日
回答済み: Ameer Hamza 2020 年 3 月 8 日
here is my code
x=('input x')
y=x^+2
how do I ask once I get my output if I want the calculation to be repeated again
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 3 月 8 日
Which calculation do you want to repeat?
matt noman
matt noman 2020 年 3 月 8 日
what I want is that after I enter an x and the first calculation happens I want to make a menu of yes and no that asks if I would like to repeat the program if I say no I want the program to end but if I say yes I want to input another value into x and repeat that calculaton again

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 3 月 8 日
This is a general structure of what you are trying to do
condition = true;
while condition
x = input('Enter a number: ');
y = x.^2;
disp(y);
condition = input("Do you want to continue? (yes/no)\n", 's') == "yes";
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by