140k views
1 vote
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.

1 Answer

3 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 Eriola
by
4.1k points