我已經把它轉過來了,所以你不會幫我作弊。只是想知道,如果這看起來正確:僞代碼檢查。需要轉讓的驗證
分配: 輸入員工的姓名和工資的列表,並確定 均值(平均)工資,以及上述工資和 低於平均值的數量。
的計劃: 允許低於平均
計數值的姓名和工資 計算平均 排序值高於平均值 計數值輸入//This program will allow a user to input an employee name and salary
//The output will contain the mean salary
//as well as the number of salaries above and below the mean
//
//Arrays Used:
//Name(K) = Array for employee names
//Salary(K) = Array for salaries
//
//Variables Used:
//Mean = Mean of all employees Salaries
//UpMean = Number of Employees making more than the mean
//DwnMean = Number of Employees making less than the mean
//Sum = Sum of all salaries
//CountM = Counter for Mean
//CountUp = Counter for # of salaries above mean
//CountDwn = Counter for # of salaries below mean
Main
Call WelcomeMessage
Call InputData
Call Calculate
Call OutputData
End Program
WelcomeMessage
Write, 「Beginning the Salary Program」
End WelcomeMessage
InputData
Declare Name(100) Of Strings
Declare Salary(100) Of Real
Declare Mean, UpMean, DwnMean As Real
Set Sum = 0
Set CountM = 0
Set CountUp = 0
Set CountDwn = 0
Write, "Enter Employee name and Salary."
Write, "Enter *,0 when done."
Input Name(K), Salary(K)
While Name(K) <> "*"
Set CountM = CountM + 1
Set Sum = Sum + Salary
Write, "Enter Employee name and Salary."
Write, "Enter *,0 when done."
Input Name(K), Salary(K)
End While
End InputData
Calculation
//Here Mean is found
Set Mean = Sum/CountM
//Here Number of Employees making more than the mean is found
For K = Step 1 to CountM
If Salary(K) > Mean Then
Set CountUp = CountUp + 1
End If
//Here Number of Employees making more than the mean is found
Set CountDwn = CountM - CountUp
//The above algorythm doesn't account for the possibility
//of someone making exactly the average so subtract 1 to reconcile
If Salary(K) = Mean Then
Set CountDwn = CountDwn - 1
End If
End Calculation
OutputData
Write, "There were," CountM, "salaries entered."
Write, "The mean salary is:", Mean
Write, "There are", CountUp, "employees who make more than the average"
Write, "There are", CountDwn, "employees who make less than the average"
End OutputData
我真的不認爲像do ...這樣的指令(true),在代碼中有一個break語句,是教會一個新人的好方式。代碼應該是自我記錄的,這裏的執行流程很難遵循。 – jkeys 2009-06-14 04:32:44