How to Get a script to end if a certain input is entered
Show older comments
I am new to MATLAB, and I have a general question about getting a script to end when an input is entered that does not fulfill the requirements. I know that it requires some sort of "for" statement, but i'm not sure how to inplement this.
I am currently working on a problem that I can use as an example:
Create a script that asks the user repeatedly for two time intervals in the form of hours, minutes, and seconds, and provides the addition of these two time intervals in the same form. The script should end if the input from the user is zero for all six values. You should write a function which takes in the given time intervals and returns their addition. The script will handle the user input, call the function, and display the corresponding output.
This is what I have so far:
clc
clear
flag = true;
while flag
disp('Do you want to enter a time interval?')
answer = input('Enter 1 for YES and 0 for NO :')
if answer == 1
hms1 = input("Enter the first time interval using 6 digits representing hours, minutes, and seconds: ");
hms2 = input("Enter the second time interval using 6 digits representing hours, minutes, and seconds: ");
intervalAddition(hms1, hms2);
disp(hms1);
disp(hms2);
else
flag = false;
end
end
How do i get the script to end if the input is zero for all six values?
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!