find the errors\neach of the following programs has errors. find as many as you can.\n58. // this program…

find the errors\neach of the following programs has errors. find as many as you can.\n58. // this program averages 3 test scores.\n// it uses the variable perfectscore as a flag.\ninclude <iostream>\nusing namespace std;\nint main()\n{\n cout << \enter your 3 test scores and i will \;\n << \average them:\;\n int score1, score2, score3;\n cin >> score1 >> score2 >> score3;\n double average;\n average = (score1 + score2 + score3) / 3.0;\n if (average = 100);\n perfectscore = true; // set the flag variable\n cout << \your average is \ << average << endl;\n bool perfectscore;\n if (perfectscore);\n {\n cout << \congratulations!\\n\;\n cout << \thats a perfect score.\\n\;\n cout << \you deserve a pat on the back!\\n\;\n return 0;\n }\n}

find the errors\neach of the following programs has errors. find as many as you can.\n58. // this program averages 3 test scores.\n// it uses the variable perfectscore as a flag.\ninclude <iostream>\nusing namespace std;\nint main()\n{\n cout << \enter your 3 test scores and i will \;\n << \average them:\;\n int score1, score2, score3;\n cin >> score1 >> score2 >> score3;\n double average;\n average = (score1 + score2 + score3) / 3.0;\n if (average = 100);\n perfectscore = true; // set the flag variable\n cout << \your average is \ << average << endl;\n bool perfectscore;\n if (perfectscore);\n {\n cout << \congratulations!\\n\;\n cout << \thats a perfect score.\\n\;\n cout << \you deserve a pat on the back!\\n\;\n return 0;\n }\n}

Answer

Explanation:

Step1: Pre - processor directive error

The include statement should be #include <iostream> with a # at the start.

Step2: Variable declaration and usage error

The variable perfectScore is used before it is declared in the if (average = 100); line.

Step3: Assignment vs comparison error

In if (average = 100);, the single equal sign (=) is an assignment operator. It should be == for comparison.

Step4: Semicolon after if block error

The semicolon after if (average == 100); and if (perfectScore); makes the if statements have an empty body, and the subsequent code blocks are not part of the if logic as intended.

Answer:

  1. include <iostream> should be #include <iostream>.
  2. perfectScore is used before declaration.
  3. if (average = 100); should be if (average == 100).
  4. Unnecessary semicolons after if statements (if (average == 100); and if (perfectScore);).