Using while loop: Unable to obtain value

6 ビュー (過去 30 日間)
Danny Allen
Danny Allen 2021 年 1 月 26 日
コメント済み: Danny Allen 2021 年 1 月 26 日
I'm trying to use a while loop and continue getting the request to input a "bad thickness value, re-enter" from my code. I'm not sure what I'm doing wrong, or if I'm just not accoutning for something.
diameter = 10.2; %the sphere outer diameter
thick = input('enter thickness of sphere');
while (thick <= 0)
thick = input('bad thickness value, re-enter')
end
density = 1.25;
Rout = diameter/2;
Rin = diameter/2 - thick;
Volume = 4/3*pi*(Rout^3-Rin^3);
%mass = density*volume
mass = density*Volume;
%weight = mass*g
g = 9.81;
weight = mass*g;
disp(['The sphere''s weight is= ', num2str(weight)])
enter thickness of sphere -0.2
%the line below is what I don't understand, I thought the while loop took care of it?
bad thickness value, re-enter

採用された回答

David Hill
David Hill 2021 年 1 月 26 日
編集済み: David Hill 2021 年 1 月 26 日
The code is working properly. If you enter a negative number or zero, the code prompts you to reenter a correct value.
  1 件のコメント
Danny Allen
Danny Allen 2021 年 1 月 26 日
Thank you so much for checking it! I was a little confused and after watching a few videos I understand a bit more now! Thank you again.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by