Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
For some strange reason MATLAB spits out two answers to the following code , pay2 =, and p =. It is ony supposed to produce 1 answer
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
The following code is spitting out two answers, and it's only supposed to produce one answer, payment.
Instead it spits out a value for pay2 first as well as one for payment. I only want an answer for payment.
Problem 2 (fare):
Testing with argument(s) 4, 44
Feedback: Your function performed correctly for argument(s) 4, 44
Testing with argument(s) 1, 20
Feedback: Your function performed correctly for argument(s) 1, 20
Testing with argument(s) 1, 11
Feedback: Your function performed correctly for argument(s) 1, 11
Testing with argument(s) 0.2, 67
Feedback: Your function performed correctly for argument(s) 0.2, 67
Testing with argument(s) 0.9, 55
Feedback: Your function performed correctly for argument(s) 0.9, 55
Testing with argument(s) 1.45, 17
Feedback: Your function made an error for argument(s) 1.45, 17
Your solution is _not_ correct.
function payment = fare(miles,age)
pay1 =0;
pay2=0;
pay3=0;
if miles <= 1
pay1 = 200;
payment = pay1;
elseif miles <=20
pay1= 200;
pay2 = (miles-1)*0.25*100
payment = pay1+pay2;
elseif miles>20
pay1 = 200
pay2 = (miles-1)*0.25*100
pay3 = (miles-10)*0.10*100
payment = pay1+pay2+pay3;
end
payment = (pay1+pay2+pay3)/100;
if age <=18 || age>=65
payment = (pay1+pay2+pay3)*0.8/100;
else
payment=(pay1+pay2+pay3)/100;
endend
1 comentario
Stephen23
el 27 de Nov. de 2016
Duplicate:
https://www.mathworks.com/matlabcentral/answers/314071-i-m-getting-two-answer-from-my-function-i-only-want-one-how-do-i-fix-this
Respuestas (2)
Steven Lord
el 27 de Nov. de 2016
You have several lines inside the elseif sections of your code that do not end in semicolons. Add the semicolons at the end of those lines to suppress the display.
0 comentarios
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!