How to use for loop

4 visualizaciones (últimos 30 días)
Inifome Eleluwor
Inifome Eleluwor el 11 de En. de 2021
Comentada: Inifome Eleluwor el 11 de En. de 2021
Hello, I'm supposed to make a code that prompts the user to enter a positive real number to 1 decimal place. I should prompt the user 10 times. This was the code I used.
user_input = fprintf('%.1f', input('Enter a positive real number'));
for i = 1:10
if user_input <= 0
user_input = fprintf('%.1f', input('Enter a positive real number'));
end
end

Respuesta aceptada

WalterWhite
WalterWhite el 11 de En. de 2021
user_input = fprintf('%.1f\n', input('Enter a positive real number\n'));
for i = 1:9 %first input outside the loop;so 9 more inputs
if user_input >= 0
user_input = fprintf('%.1f\n', input('Enter a positive real number\n'));
end
end
  1 comentario
Inifome Eleluwor
Inifome Eleluwor el 11 de En. de 2021
thank you for your answer. Very appreciated.

Iniciar sesión para comentar.

Más respuestas (1)

KSSV
KSSV el 11 de En. de 2021
user_input = fprintf('%.1f\n', input('Enter a positive real number'));
count = 0 ;
while count <= 10
if user_input >= 0
count = count+1 ;
user_input = fprintf('%.1f\n', input('Enter a positive real number'));
end
end
  1 comentario
Inifome Eleluwor
Inifome Eleluwor el 11 de En. de 2021
thank you for your answer. Very appreciated.

Iniciar sesión para comentar.

Categorías

Más información sobre Point Cloud Processing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by