Question

In: Computer Science

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

/* Homework Lab 6

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. It will say "Congratulations!" even when not perfect.

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. The output
will still display a zero after the decimal point even if it should be .3 or .7...

IMPORTANT NOTE ON ERROR #3: You are NOT allowed to change the data type of any constant
or variable to make this work. You also MUST divide by NUM_OF_SCORES
when calculating the average.
*/

//------------------------------------------------------------------------------
#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);
       cout << "Congratulations! Those are all perfect scores" << endl;
   else
       cout << "Not perfect yet - Better luck next time." << endl;

   cout << endl;

   return 0;
}

/* Sample program interactions:
------------------------------------------------------------------------------
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 . . .

*/

Solutions

Expert Solution

#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 = (double)(score1 + score2 + score3) / NUM_OF_SCORES;//eoror3 type casting needed
cout << fixed << showpoint << setprecision(1);
cout << "Your average is " << average << endl;

// Follow up with a message.
if (average == 100)//error1 is semicolon at end and error 2 is relational operator "==" is requried, because '=' operator assigns 100 not checks the condition
cout << "Congratulations! Those are all perfect scores" << endl;
else
cout << "Not perfect yet - Better luck next time." << endl;

cout << endl;

return 0;
}


Related Solutions

You will create a program with 3 methods. For the previous homework with three problems, you...
You will create a program with 3 methods. For the previous homework with three problems, you will create a method for each problem. In the main method, you will declare the three arrays and create the memory space for each of them. The first method will receive a one dimension array and then it will assign the values ( e.g., a[4] = 4*4*4*4;). The second method receives a 2 dimensional array and creates the calendar. The third method receives a...
Exercise 20-23 (Algo) Error correction; three errors [LO20-6] Below are three independent and unrelated errors. On...
Exercise 20-23 (Algo) Error correction; three errors [LO20-6] Below are three independent and unrelated errors. On December 31, 2020, Wolfe-Bache Corporation failed to accrue salaries expense of $2,300. In January 2021, when it paid employees for the December 27–January 2 workweek, Wolfe-Bache made the following entry: Salaries expense 2,300 Cash 2,300 On the last day of 2020, Midwest Importers received a $100,000 prepayment from a tenant for 2021 rent of a building. Midwest recorded the receipt as rent revenue. The...
Detect the errors in the following program? How many errors do you observe in the following...
Detect the errors in the following program? How many errors do you observe in the following line of code? Clearly explain what these errors are and how they can be fixed? (Note that this program has only three lines of code). Please type your program in the following textbox. for i in Range(1,20.0): if i%2=0: print(i) This is a python program
Problem 22-6 The MediQuick lab has three lab technicians available to process blood samples and three...
Problem 22-6 The MediQuick lab has three lab technicians available to process blood samples and three jobs that need to be assigned. Each technician can do only one job. The table below represents the lab's estimate (in dollars) of what it will cost for each job to be completed. JOB TECH A TECH B TECH C J-432 9 10 8 J-487 9 6 7 J-492 12 7 10 Assign the technicians to the jobs to minimize costs. Job Tech Minimum...
- In general, the occurrence of errors (errors) in a program can be classified in four...
- In general, the occurrence of errors (errors) in a program can be classified in four categories. List and explain, then give an example, of each mistake (error)! and also - It is known that: S -> aB | bA A -> a | aS | bAA B -> b | bS | aBB Derivation for the string aaabbabbba Provide a solution for its derivation and syntax analysis. Please explain it with easy understandable method, because im still in learning...
COMPUTER SCIENCES HOMEWORK Assume it takes 10-6 seconds to do a unit of work. 10 100...
COMPUTER SCIENCES HOMEWORK Assume it takes 10-6 seconds to do a unit of work. 10 100 1,000 10,000 100,000 1,000,000 n n2 log10(n) 2n In each cell in this table put the length of time it would take to complete an algorithm with the given work formula and the given size. Take the time to represent large numbers in reasonable values; eg. report 109 seconds as 25 hours PLEASE HELP!!
Homework (Submit in groups) You are 20 and plan to work for 45 years until you...
Homework (Submit in groups) You are 20 and plan to work for 45 years until you retire at 65. You expect to live until you are 90. You will collect a pension. Your annual pension payment will be equal to your final salary times a 3% crediting rate times the number of years that you work. Your starting salary (paid at the end of the year) is $40,000. You expect to get a 4% annual raise. Your discount rate is...
What is the PACE PROGRAM? Who does it benefit, how does it work, etc?
What is the PACE PROGRAM? Who does it benefit, how does it work, etc?
What java program would you write to solve the following problems and why does it work?...
What java program would you write to solve the following problems and why does it work? Please also comment on other students’ code at least three times. 1) Implement MyArrayStack (constructor, push, pop, peek and isEmpty), and MyLinkedQueue with both next and previous pointers (constructor, enqueuer/offer, dequeuer/poll, peek and isEmpty), and write the following two program to test them. You must use MyArrayList or MyLinkedList for the implementation. 2) For stack testing, write a program to check if a string...
Need a description what does this program does and how does it work. #include <iostream> using...
Need a description what does this program does and how does it work. #include <iostream> using namespace std; double function(int num, double* memorize); int main() {        int num=5;        char cont;        double* memorize = new double[num + 1];        do {               cout << "Enter n ";               cin >> num;               memorize[1] = 1;               memorize[2] = 1;               memorize[3] = 1;               memorize[4] = 3;               memorize[5] = 5;               for (int i = 6; i...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT