题目要求
编写一个比赛得分程序。共有7 个评委,按百分制打分,计分
原则是去掉一个最高分和一个最低分,求平均值。要求:
- 评委的打分以十进制从键盘输入。
- 成绩以十进制给出,并保留 1位小数。
- 输入输出时屏幕上要有相应提示
完整代码
DATAS SEGMENT;此处输入数据段代码inputMsg db 'please input$'errMsg db 0ah, 0dh, 'please input 0-100$'finalMsg db 0ah, 0dh, 'the score is $'score DB 30H DB 0 DB 30H DUP('$')realScore dw 0minScore dw 100maxScore dw 0count dw 0
DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码
STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS
START:MOV AX,DATASMOV DS,AX;此处输入代码段代码mov ax, 0mov count, axmov maxScore, axmov ax, 100mov minScore, axmov cx, 7input:mov realScore, 0mov dx, cxadd dx, '0'mov ah, 02hint 21hlea dx, inputMsgmov ah, 09hint 21hlea dx, scoremov ah, 0ahint 21hMOV DX,0AH;回车换行MOV AH,02HINT 21HMOV DX,0DHMOV AH,02HINT 21Hcall checkInvalidloop inputjmp outputcheckInvalid procpush cxmov al, score[1]cmp al, 3ja errormov si, 2mov cl, score[1]funcCheckInvalidLop:mov ax, 0mov al, score[si]sub al, '0'cmp al, 0jb errorcmp al, 9ja errorpush axmov ax, 10mul realScoremov realScore, axpop axadd realScore, axinc siloop funcCheckInvalidLopmov dx, 0mov ax, realScorecmp ax, 100ja erroradd count, axcmp ax, minScoreja checkMaxmov minScore, axcheckMax:cmp ax, maxScorejb funcCheckInvalidRetmov maxScore, axfuncCheckInvalidRet:pop cxretcheckInvalid endpoutput:lea dx, finalMsgmov ah, 09hint 21hmov dx, 0mov ax, countsub ax, minScoresub ax, maxScoremov bx, 5div bx;AX商,DX余数push dxmov bx, 10mov cl, 0funcOutputDivLop:mov dx, 0div bxadd dl, '0'push dxinc clcmp ax, 0jne funcOutputDivLopfuncOutputOutLop:pop dxmov ah, 02hint 21hloop funcOutputOutLopmov dx, '.'int 21hpop dxsal dx, 1add dx, '0'int 21hjmp exiterror:lea dx, errMsgmov ah, 09hint 21hexit:MOV AH,4CHINT 21H
CODES ENDSEND START