Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

find the errors each of the following programs has errors. find as many…

Question

find the errors
each of the following programs has errors. find as many as you can.

  1. // 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;
}
}

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);).