How to make a program repeat a script

I'm creating this program which calculates the percentage attendance and tells if the student has short attendance or not. Total number of lectures are 36 so I want it to give error if attended lectures (input) are more than 36. How can I make it repeat the program for another input if a>36.
clc
t=36; %total number of lectures
p=input('Enter Number of Lectures Attended \n');
a=(p/t)*100; % this calculates the percentage attendance
if p>36
fprintf('Error, note that the total number of lectures are 36. \n')
elseif (a>=75)
fprintf('The student does not have short attendace. \n')
else
fprintf('The student has short attendace. \n')
end

 Respuesta aceptada

Cris LaPierre
Cris LaPierre el 27 de Mzo. de 2021

1 voto

Sounds like you need a loop. There are two type - for and while. If you know the number of times you want to loop through your code, a for loop is generally the better choice.
You can learn more about for loops in Ch 13 of MATLAB Onramp.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Preguntada:

el 27 de Mzo. de 2021

Respondida:

el 27 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by