I need a check on my answers
1) prompt a user to enter an employee name, employee id, and hours worked until a value of "-1" is entered for employye name.
my answer:
Start
Declarations
num EmployId, HrsWrked
string EmployName
housework()
detailLoop()
Stop
housework()
output "Please enter Employee Name"
input EmployName
output "Please enter Employee ID number"
input EmployId
output "Please enter Hours Worked"
input HrsWrked
return
detailLoop()
check if EmployName = -1
while EmployName < > -1
output "Please enter Employee Name"
input EmployName
output "Please enter Employee ID number"
input EmployId
output "Please enter Hours Worked"
input HrsWrked
check if EmployName = -1
endwhile
return
2) If the employee id is not between 1 and 599, continue to prompt the user until a valid employee id is entered.
my answer:
Start
Declarations
num EmployId, HrsWrked
string EmployName
housework()
detailLoop()
Stop
housework()
output "Please enter Employee Name"
input EmployName
output "Please enter Employee ID number"
input EmployId
output "Please enter Hours Worked"
input HrsWrked
return
detailLoop()
check if EmployName = -1
while EmployName < > -1
check if EmployID is >= 1 and <= 599
if EmployID is <1 or > 599
output "Incorrect Employee ID number, Please enter ID value 1- 599"
input EmployId
endif
output "Please enter Employee Name"
input EmployName
output "Please enter Employee ID number"
input EmployId
output "Please enter Hours Worked"
input HrsWrked
check if EmployName = -1
endwhile
return
1 answer
For the first part, the code is generally correct, but I suggest making change to avoid the following dialog:
Please enter Employee Name
-1
Please enter Employee ID number
123456789
Please enter Hours Worked
0
Goodbye
Once the Employee Name is entered as -1, users expect to either quit the program or see the "goodbye" message.
They would be wondering what's the point of entering EmployeeID and hours worked, which are no longer relevant.
For number 2, it's a similar comment. In addition, the entry of EmployeeID can be modified to let the user immediately correct the ID right after he entered an invalid one, such as:
output "Please enter Employee ID number"
input EmployId
while EmployID is <1 or > 599
output "Incorrect Employee ID number, Please enter ID value 1- 599"
input EmployId
endwhile
This will take care of the problem on the spot.
Otherwise, the pseudocode looks quite logical.