solve the pascal problem

2008-11-24 3:17 am
Write a program, using for–repeat nested loop, to accept salaries from the user and calculate the average salary. The following algorithm would be adopted:


1. Ask the user to enter the total number of months.

2. Ask the user to enter the monthly salary one by one.

3. Check if the salary amount is between $5,000 and $20,000 inclusively.

4. If the amount exceeds the range, print an error message and require the user to re–enter the amount.

5. Output the average salary.


A sample program output is shown below:

Enter the total number of months: 3



Enter salary for month 1: 15000

Enter salary for month 2: 3000

Out of range

Enter salary for month 2: 30000

Out of range

Enter salary for month 2: 7000

Enter salary for month 3: 11000



The average salary is 11000.00

回答 (1)

2008-11-24 6:31 am
✔ 最佳答案
又係我ar,為左激發下你ge思考
比D提示你

Let Number of month inputted by user as N;
Declare total, userInput as integer;
Initialize i = 0;
你要用個while loop (i<N)做以下的工作
1. read user input of the salary and store it in variable "userInput";
2. if (userInput >= 5000 and userInput<=20000){ total = total plus userInput; i = i plus 1;} else {write errormessage;}

最後就係write userInput / N;


仲有唔明ge話不妨提出大家研究下
參考: 大學電腦系的學生


收錄日期: 2021-04-13 16:16:10
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20081123000051KK01923

檢視 Wayback Machine 備份