How do i end my code

4 vues (au cours des 30 derniers jours)
My mee
My mee le 20 Juil 2021
Réponse apportée : Jan le 20 Juil 2021
How do i end my code even though I got the answer already? this is the code
function circular
r = input("Enter the Radius: ");
disp("Circumference is ");
disp(2*pi*r);
disp("Area is ");
disp(pi*r*r);
disp("Volume is ");
disp((4*pi*r*r*r)/(3));
end
THERE IS AN EXAMPLE OF MY PROBLEM IN THIS CODE
Enter the Radius:
1
Circumference is
6.2832
Area is
3.1416
Volume is
4.1888
Enter the Radius: (it still asks me to enter an input)
  2 commentaires
Rik
Rik le 20 Juil 2021
How do you call this function?
My mee
My mee le 20 Juil 2021
this is actually only a part of the entire code im making since it's a menu driven code

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 20 Juil 2021
You have showed some code, which runs once only. The output shows, that this function is called again afterwards, but we do not see, from where. But there is the point to modify your program.
The loop in the calling code might look like this:
function main
while 1
circular
end
end
Then modify this loop and insert a test inside the function, if an invalid input is chosen:
function main
proceed = true;
while proceed
proceed = circular;
end
end
function proceed = circular
r = input("Enter the Radius (hit return to stop: ");
proceed = ~isempty(r);
if ~proceed % Stop and reply FALSE
return;
end
disp("Circumference is ");
disp(2*pi*r);
disp("Area is ");
disp(pi*r*r);
disp("Volume is ");
disp((4*pi*r*r*r)/(3));
end

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by