168k views
4 votes
// This pseudocode should create a report that contains an

// apartment complex rental agent's commission. The
// program accepts the ID number and name of the agent who
// rented the apartment, and the number of bedrooms in the
// apartment. The commission is $100 for renting a three-bedroom
// apartment, $75 for renting a two-bedroom apartment, $55 for
// renting a one-bedroom apartment, and $30 for renting a studio
// (zero-bedroom) apartment. Output is the salesperson�s
// name and ID number and the commission earned on the rental.
start
Declarations
num salesPersonID
string salesPersonName
num numBedrooms
num COMM_3 = $100.00
num COMM_2 = $75.00
num COMM_1 = $55.00
num COMM_STUDIO = $30.00
num QUIT = 9999
getReady()
while salesPersonID <> QUIT
detailLoop()
endwhile
finish()
stop

getReady()
output "Enter salesperson ID or ", QUIT, " to quit "
output salesperson_ID
return

detailLoop()
output "Enter name "
input salesPersonName
output "Enter number of bedrooms rented "
input numBedrooms
if numBedrooms > 3 then
commissionEarned = COMM_3
else
if numBedrooms < 2 then
commissionEarned = COMM_2
else
if numBedrooms > 1 then
commission = COMM_1
else
commission = COMM_4
endif
endif
endif
output salesPersonID, salesPersName, commissionEarned
output "Enter salesperson ID or ", QUIT, " to quit "
input salesPersonID
return

finish()
output "End of report"
return

User Tom Auger
by
7.8k points

1 Answer

4 votes

Step-by-step explanation:

what is the question ?

are we to find the mistakes in the code and fix them ?

if so,

the mistakes :

there is no initial input for the ID number. and "salespersonID" is not initialized. depending on the system this will either crash at runtime or deliver a phantasy number.

COMM_4 is not declared. and probably not needed.

the if-statements use wrong equality and inequality signs.

the agent gets the COMM_3 commission for exactly 3 bedrooms (not more than 3 bedrooms). similar for 2 and 1 bedrooms. the 0 bedroom (studio) possibility is not covered at all.

the possible option of more than 3 bedrooms is not covered in the function specification at all. we have to conclude that this case cannot happen, but our function does not check and reject this potential (and erroneous) user input.

commissionEarned and commission are not declared (and it means that the earned commission is stored at 2 different places depending on the earning level, making this inconsistent and confusing and probably wrong in the overall context).

the corrections :

num commissionEarned

getReady()

output "Enter salesperson ID or ", QUIT, " to quit "

input salesperson_ID

return

commissionEarned = 0

if numBedrooms == 3 then

commissionEarned = COMM_3

else

if numBedrooms == 2 then

commissionEarned = COMM_2

else

if numBedrooms == 1 then

commissionEarned = COMM_1

else

if numBedrooms == 0 then

commissionEarned = COMM_STUDIO

else

output "The entered number of bedrooms is invalid. Try again !"

endif

endif

endif

endif

User Alijvhr
by
8.4k points