Find the errors in following program This program averages t

Find the errors in following program.

//This program averages three test scores.

//It uses variable perfectScore as a flag.

#include <iostream>

uisng namespace std;

int main()

{

            cout<<\"Enter your three 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<<\"That\'s a perfect score.\ \";

                        return 0;

            }

Solution

The errors are specified as comments. Here are the errors identified for you:

#include <iostream>   //include header: No Error.
using namespace std;   //includes namespace. \"using\" is misspelled.

int main()       //Defines main(): No error.

{
cout<<\"Enter your three test scores and I will \"   //Prints to screen. This is not an end of string, and should not be terminated with semicolon(;)
<<\" average them: \";  

int score1, score2, score3;   //Declares 3 integers. This is an end of statement, and should end with semicolon.

cin>>score1>>score2>>score3;   //Reads 3 integer values.

double average;       //Declares a double variable average.

average = (score1 + score2 + score3) / 3.0;   //Calculates the average of three scores entered.

bool perfectScore;   //This is where it should be declared.
if (average == 100)   //This is a comparison and not assignment. So, should have double equals (==) sign, and should not end with semicolon(;)
perfectScore = true; // set the flag variable   This variable should be declared before usage.
cout<<\"Your average is \"<<average <<endl;   //Prints average to screen: No error.

//bool perfectScore;   This should not be here, but before its first usage.

if (perfectScore)   //This is a conditional, and should not be terminated with ;

{

cout<<\"Congratulations!\ \";       //Prints this to screen.: No Error.
cout<<\"That\'s a perfect score.\ \";   //Prints this to screen.: No Error.
return 0;       //Returns 0: No Error.

}   //if block closed.
}   //main() method should be closed.

Find the errors in following program. //This program averages three test scores. //It uses variable perfectScore as a flag. #include <iostream> uisng name
Find the errors in following program. //This program averages three test scores. //It uses variable perfectScore as a flag. #include <iostream> uisng name

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site