Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Whats wrong with my code,I'm not able to get though my test if the month is 12?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Vijayramanathan B.tech-EIE-118006077
el 11 de Feb. de 2018
Cerrada: MATLAB Answer Bot
el 20 de Ag. de 2021
4. Write a function called day_diff that takes four scalar positive integer inputs, month1, day1, month2, day2. These represents the birthdays of two children who were born in 2015. The function returns a positive integer scalar that is equal to the difference between the ages of the two children in days. Make sure to check that the input values are of the correct types and they represent valid dates. If they are erroneous, return -1. An example call to the function would be >> dd = day_diff(1,30,2,1); 2 which would make dd equal 2. You are not allowed to use the built-in function datenum or datetime.
function a = day_diff(month1,day1,month2,day2)
if ((month1 && month2)==(1 || 3 || 5 || 7 || 8 || 10 || 12))
month1 = month1*31;
month2=month2*31;
else if ((month1 && month2)==(4 || 6 || 9 || 11))
month1 = month1*30;
month2=month2*30;
else
month1=28;
month2=28;
end
end
finday1=month1+day1;
finday2=month2+day2;
a=abs(finday1-finday2);
end
5 comentarios
Geoff Hayes
el 11 de Feb. de 2018
also look at
month1 = month1*31;
month2 = month2*31;
If month1 is 1 (January) and month2 is 12 (December), what is the intent of the above code? It is almost as if you are assuming that every month has 31 days (12*31) and then the
a=abs(finday1-finday2);
would make sense. But that assumption is invalid...
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!