repeat function and calculation

조회 수: 11 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by