Lesson 50: Find the errors
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Be the tester
- Every exam has an algorithm with errors in it: find each error and write the correction.
- Here the algorithms are C++ programs you can run. Run each one first and compare what it does with what it should do.
- Change one thing at a time, then run again.
Words for this lesson
| Word | Meaning |
|---|---|
| syntax error | breaks the rules of the language: the program does not compile |
| logic error | the program runs but gives the wrong result |
| test data | inputs with a known correct answer |
| trace | follow the program line by line with the values |
English
A good way to find errors
| Step | What to do |
|---|---|
| 1 | Read what the program should do. |
| 2 | Run it with test data you can check by hand. |
| 3 | Find the first wrong output and the line that made it. |
| 4 | Fix one error, then test again. |
English
In the exam
- 0478/22/F/M/24 Q5(a): a profit algorithm has three errors. Mark scheme: line 05 OUTPUT should be INPUT; line 06 OR should be AND; line 10 NEXT should be ENDIF. Your first program has the first two errors in C++ (the third is a C++ sum the wrong way round, because a wrong end of block would not compile).
- 0478/22/M/J/23 Q7(b): a check-digit algorithm has three errors. Mark scheme: the total must use Number[Counter], not Number; the stop test must look for −1; the output loop must start at 1, not 0. Your second program has the same kind of errors: the first element instead of each element, and an output loop with the wrong range.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
This program should input a cost price and a selling price, then output the profit (selling price − cost price). An input of 0 for either price stops it. It has three errors. Find them and correct them. Check types 50 and 80 (profit 30), 20 and 15 (profit −5), then 0 and 40 (no profit line, the program stops).
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
This program should add a check digit to a 4-digit code (lesson 41): each digit times its place, then the last digit of the total. It has two errors. Find them and correct them. 3216 must give Code: 32164 및 5072 must give Code: 50724.
출력을 보려면 '실행'을 클릭하세요.