182,805 views
39 votes
39 votes
a machine administers medication dosage based on weight. write an if-elseif-else statement that assigns the appropriate dosageamount given userweight. weight (kg) dosage (units) --------------------------------------------------------- less than 50 10 50 - 140 20 greater than 140 30 ex: if userweight is 65, then dosageamount is assigned with 20.

User Kich
by
2.8k points

1 Answer

21 votes
21 votes

Answer:

MATLAB function:

function dosageAmount=CalculateDosage(userWeight)

% user weight is in kg

dosageAmount=0;

% clears the variable dosageAmount

if userWeight<50

dosageAmount=10;

elseif userWeight <= 140

dosageAmount=20;

else

dosageAmount=30;

end

end

Code: >> CalculateDosage(65)

Refer to the image for more

a machine administers medication dosage based on weight. write an if-elseif-else statement-example-1
User Cwoebker
by
3.3k points