QUESTION IMAGE
Question
find the errors
each of the following programs has errors. find as many as you can.
- // this program averages 3 test scores.
// it uses the variable perfectscore as a flag.
include <iostream>
using namespace std;
int main()
{
cout << \enter your 3 test scores and i will \;
<< \average them:\;
int score1, score2, score3;
cin >> score1 >> score2 >> score3;
double average;
average = (score1 + score2 + score3) / 3.0;
if (average = 100);
perfectscore = true; // set the flag variable
cout << \your average is \ << average << endl;
bool perfectscore;
if (perfectscore);
{
cout << \congratulations!\
\;
cout << \thats a perfect score.\
\;
cout << \you deserve a pat on the back!\
\;
return 0;
}
}
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.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
include <iostream>should be#include <iostream>.perfectScoreis used before declaration.if (average = 100);should beif (average == 100).- Unnecessary semicolons after
ifstatements (if (average == 100);andif (perfectScore);).