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}
Answer
Explanation:
Step1: Missing semicolon after variable declaration
The line int score1, score2, score3, should be int score1, score2, score3;
Step2: Incorrect assignment operator in 'if' condition
The line if (average = 100); should use the equality - comparison operator == instead of the assignment operator =, so it should be if (average == 100);
Step3: Using variable before initialization
The variable perfectScore is used in the line perfectScore = true; before it is declared. It should be declared before this assignment.
Step4: Unnecessary semicolon after 'if' condition
The line if (perfectScore); has an unnecessary semicolon which will cause the block following it to not be part of the if - statement. It should be if (perfectScore) without the semicolon.
Step5: Return statement in wrong scope
The return 0; statement is inside the if - block for perfectScore. It should be at the end of the main function, outside of this if - block.
Answer:
- Missing semicolon after
int score1, score2, score3,. - Incorrect assignment operator in
if (average = 100);. - Using
perfectScorebefore declaration. - Unnecessary semicolon after
if (perfectScore);. return 0;in wrong scope.