I need to know if I'm doing this right. I just recently started Psuedocoding and I'm still confused about it. If I was to test this code would it work?



Declare Employees[100] as String

Declare Salaries[100] as Integer

Declare K as Integer

Declare Average as Integer

Set Sum = 0

Set K = 1  

Set Average = 0 

Write "Enter Total Employee Count." 

Input Employees 

FOR K = 1 Add 1 to Average Then


     Write "Enter the Employee Name and salary" 
     Input Name, Salary 
     Set Employees[K]=Name 
     Set Salaries[K]=Salary 
     Set Sum=Sum+Salary 

END FOR

Set Average=Sum/Average

Set Below = 0 

Set Above = 0

If K = Add 1 to Average Then 

    If Salaries=[K] < Average Then 
     Set Below = Below + 1 
    End If

    If Salaries=[K] > Average Then 
     Set Above = Above + 1 
    End If 

END If

What do you need help with?

I need to know if I'm doing this right. I just recently started Psuedocoding and I'm still confused about it. If I was to test this code would it work?

Input Employees 

What does Input accomplish when the variable is an array?

FOR K = 1 Add 1 to Average Then

Average is 0 at this point, so your loop would never execute. If the goal is to populate the arrays, it should be either this:

FOR K = 1 Add 1 to 100 Then

Or something else that takes advantage of the Input Employees result. I'd suggest a separate count variable for the number of employees to use in your for loop. Note that your code doesn't validate any input. What happens if I type 0 or 101 for the number of employees?

Set Average=Sum/Average

Average is still 0, so you're dividing by 0 here. To get an average you need to divide the sum by the count of items. In this case, K. Also note that Average is an integer, which mathematically means you don't get sub-zero precision.

If K = Add 1 to Average Then

Is this a loop? If not, why are you adding to your average? Won't that skew the results?

If Salaries=[K] < Average Then

This strikes me as a syntax error, you have a rogue = in your array index.

Minor nitpick, your code doesn't output anything, so how would you know that the code accomplishes anything?

Otherwise, looks fine. The pseudocode is reasonably clean and the logic is sensible in that I understand what you were going for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.