not enough input arguments

Hello, here is my simple equation of a function to determine total pay after taxes. I'm new to Matlab and i'm getting an error in line 5 but im not really understanding why.
-------------------------------------------------------------------------------------
function [takehome_pay, taxes_paid, total_pay] =
PaycheckFunction(HoursWorked, HourlyWage, TaxRate)
end
% Function to determine your take home pay after taxes are taken out
total_pay = HoursWorked * HourlyWage;
taxes_paid = total_pay * TaxRate;
takehome_pay = total_pay - taxes_paid;
Not enough input arguments.
Error in PaycheckFunction (line 5)
total_pay = HoursWorked * HourlyWage;

Respuestas (2)

Cris LaPierre
Cris LaPierre el 22 de Abr. de 2024

0 votos

It looks like the end is in the wrong place. Move it to the bottom of your function.
function [takehome_pay, taxes_paid, total_pay] = PaycheckFunction(HoursWorked, HourlyWage, TaxRate)
% Function to determine your take home pay after taxes are taken out
total_pay = HoursWorked * HourlyWage;
taxes_paid = total_pay * TaxRate;
takehome_pay = total_pay - taxes_paid;
end
Walter Roberson
Walter Roberson el 22 de Abr. de 2024

0 votos

You are trying to run the function by pressing the green Run button. When you run the function by pressing the green Run button, the function is executed with no parameters.
MATLAB will never go searching in the environment to try to find values for variables that are named as parameters on the function line. You always have to supply any necessary values when you call the function.
Go down to the command line and invoke the function passing in appropriate values.

Categorías

Más información sobre Function Creation en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Abr. de 2024

Respondida:

el 22 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by