There were a couple of statements in your code that we do not use. For I = 0 to N-1 and the Next statement. See my comments within the code. Thank you for help and prompt response.
- 1. Declare N as Integer = 20 //number of employees
- 2. Declare Names[N] as String //array to hold names of employees
- 3. Declare Salary[N] as Float //array to hold salaries of employees
- 4. Declare TotalSalary as Float //variable to store total salary
- 5. Declare AverageSalary as Float //variable for average salary
- 6. Declare CountAboveSalaries as Integet = 0
- 7. Declare CountBelowSalaries as Integer = 0
- 8. Declare I as Integer
- 9. For I = 0 to N-1 ***I do not recognize this statement from what is being taught in the book. Is This a For Loop? The syntax we use is like: For (I = 0; I < Count; Count++) Can you rewrite it using a For Loop or a While Loop?***
//prompt user to input employee name and salary
- a. Display “Enter employee name: ”
- b. Input Names
- c. Display “Enter employee salary: ”
- d. Input Salary
//calculate total salary
- e. TotalSalary = TotalSalary + Salary
- 10. Next i I do not recognize this statement either
//calculate average salary
- 11. Set AverageSalary = TotalSalary / N
//count salaries above and below the mean
- 12. For I = 0 to N-1*** Again, please use a for loop to count***
- a. If (Salary < AverageSalary) Then
i. Set CountBelowSalaries = CountBelowSalaries + 1
- b. Else
i. Set CountAboveSalaries = CountAboveSalaries+ 1
- c. End If
- 13. Next i ***?***
- 14. Display “Mean (Average) Salary: ”, AverageSalary
- 15. Display “Number of Salaries above mean: ”, CountAboveSalaries
- 16. Display “Number of Salaries below mean: ”, CountBelowSalaries
Thank you for your quick reply. I am learning that pseudocode can be written in different ways which can make it hard on you to write it the way it is done from one book to another. Below is an example of how the book I am studying loads an array:
Write "Enter a positive number or 0 to quit"
While TempNum != 0
If TempNum < 0 Then
Write "You must enter a positive number, please try again"
Set Num[Count] = TempNum
Set Count = Count + 1
Write " Enter another number or enter 0 to quit"
Your way to code might be better, I do not know. I just want to be as consistent as possible.