(USING VISUAL STUDIOS) Ch. 7 PE 7 Paycheck(Enhanced) Write a program that asks t
ID: 2248918 • Letter: #
Question
(USING VISUAL STUDIOS)
Ch. 7 PE 7 Paycheck(Enhanced) Write a program that asks the user for # hours worked and base hourly rate, then uses nested if() statements to calculate gross pay, taxes withheld, and net pay. Use:
Overtime rate (for hours in excess of 40): 1.5x
Tax rate: 15% of first $300, 25% for the remainder.
For example, 50 hours @ $10/hr, gross pay would be 40*$10 + 10*$15 = $550. Taxes would be 0.15*$300 + 0.25*$250 =$ 107.50, net pay=$442.50.
(Example program output shown underlined):
Enter hours worked and base pay hourly rate: 50 10
Gross pay: $550.00
Tax withheld: $107.50
Net pay: $442.50
Explanation / Answer
MATLAB CODE:-
clc
clear
H = input('No.of hours worked = ');
R = input('Cost per hour $ = ');
Tr = input('Tax for first in % $300 = ');
Trm = input('Tax for remaing income in % = ');
if(H<=40)
GrI = H*R;
if(GrI<=300)
NeI = GrI - 0.01*Tr*GrI;
Tax = 0.01*Tr*GrI;
elseif(GrI>300)
NeI = GrI - 0.01*Tr*(300) - 0.01*Trm*(GrI-300);
Tax = 0.01*Tr*(300) + 0.01*Trm*(GrI-300);
end
end
if(H>40)
GrI = 40*R+(H-40)*1.5*R;
if(GrI<=300)
NeI = GrI - 0.01*Tr*GrI;
Tax = 0.01*Tr*GrI;
elseif (GrI>=300)
NeI = GrI - 0.01*Tr*300 - 0.01*Trm*(GrI-300);
Tax = 0.01*Tr*300 + 0.01*Trm*(GrI-300);
end
end
sprintf('Gross Pay $ = %0.2f Tax withheld $ = %0.2f Net Pay $ = %0.2f ',GrI,Tax,NeI)
sprintf('Tax withheld $ = %0.2f',Tax);
sprintf('Net Pay $ = %0.2f',NeI);
OUTPUT:-
No.of hours worked = 50
Cost per hour $ = 10
Tax for first in % $300 = 15
Tax for remaing income in % = 25
ans =
Gross Pay $ = 550.00
Tax withheld $ = 107.50
Net Pay $ = 442.50
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.