Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* Homework Lab This program does not work. There are three errors that you will

ID: 3851140 • Letter: #

Question

/* Homework Lab

This program does not work. There are three errors that you will need to fix:

TODO: Fix the following 3 errors.

ERROR #1) The compiler knows there is something wrong, and it will issue a
warning and and two error messages, all related to the same problem.
       Read the error and warning messages carefully to point you in the
       right direction. Did you know if you double-click on an error
       message (in the Error List) that it will take you to the spot in
       your program where the compiler detects the problem? Also, get
       in the habit of ALWAYS reading messages carefully. You may not
       understand them right now, but over time you will come to understand
       the messages better and better. One of these three messages will be
       most helpful, but it is still informative to see that the other two
       messages come as a result of this single problem.

ERROR #2) After fixing ERROR #1 your program will run. However, you will get
incorrect results.

ERROR #3)

But when you find and fix that error, something still
lurks behind that the compiler does not complain about and that will give
incorrect output.
*/

//------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;

//------------------------------------------------------------------------------

int main()
{
   int score1; // To hold three test scores
   int score2;
   int score3;
   double average; // To hold the average score

   const int NUM_OF_SCORES = 3;

   // Get the three test scores.
   cout << "Enter 3 test scores and I will average them: ";
   cin >> score1 >> score2 >> score3;

   // Calculate and display the average score.
   average = (score1 + score2 + score3) / NUM_OF_SCORES;
   cout << fixed << showpoint << setprecision(1);
   cout << "Your average is " << average << endl;

   // Follow up with a message.
   if (average == 100.0);
   {
       cout << "Congratulations! Those are all perfect scores" << endl;
   }
   if (average == 80.0);
   {

   }
   if (average == 80.0);
   {
       cout << "Not perfect yet - Better luck next time." << endl;
   }
   cout << endl;

   return 0;
}

/* Sample program interactions (2-3 different tests, with different entries):
------------------------------------------------------------------------------
BEFORE FIXING ERROR #1:
======================
The program will not run!


AFTER FIXING ERROR #1:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .


Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

AFTER FIXING ERROR #2:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

Test #3 (use calculator to see what this average should be):
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 72 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

AFTER FIXING ERROR #3:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

Test #3:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 72 80 90
Your average is 80.7
Not perfect yet - Better luck next time.

Press any key to continue . . .

*/

Explanation / Answer

Answer:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int score1;                  // To hold three test scores
    int score2;
    int score3;
    double average;              // To hold the average score

    const double NUM_OF_SCORES = 3;

    // Get the three test scores.
    cout << "Enter 3 test scores and I will average them: ";
    cin >> score1 >> score2 >> score3;

    // Calculate and display the average score.
    average = (score1 + score2 + score3) / NUM_OF_SCORES;
  
    std::cout << std::setprecision(4) << average << ' ';

    // Follow up with a message.
    if (average == 100.0)
    {
        cout << "Congratulations! Those are all perfect scores" << endl;
    }

    if (average 80.0)
    {
        cout << "Not perfect yet - Better luck next time." << endl;
    }
    cout << endl;

    return 0;
}

1) Remove semi colons after if statement.

2)Removed fixed setprecision(1) and added setprecision(2) so that 2 digits after "." will not be removed.