Find 5 errors

Please help me find 5 errors in this program!


// 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!\n";
cout << "That's a perfect score.\n";
cout << "You deserve a pat on the back!\n"; return 0;
}
@jucamohedano

Find 5 errors??

I stopped looking after finding 8. I think the problem should be, "Please help me find 5 correct programming lines in this program". THAT would be a better search.
whitenite1 is correct that there are a lot of issues with your code. Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

// 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: \n";

	double score1, score2, score3;
	cin >> score1 >> score2 >> score3;

	double average = 0;
	average = (score1 + score2 + score3) / 3.0;

	cout << "Your average is " << average << '\n';
	if (average == 100)
	{
		cout << "Congratulations! \n";
		cout << "That's a perfect score.\n";
		cout << "You deserve a pat on the back!\n";
	}	

	
	return 0;
}

Last edited on
I did found errors, but I don't know [b]how to use the variable perfectScore as a flag[/b]. If you could help me doing that I would appreciate it!

Thanks!
The best way I can think of right now, and forgive me cause I am suffering from the flu is an if/else statement. Please remember if you are using this for school work that you should try to go back to the book and your class mates as well. Also if you are going to us an IDE, you may need to pause the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>

// 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: \n";

	double score1, score2, score3;
	cin >> score1 >> score2 >> score3;

	double average = 0;
	average = (score1 + score2 + score3) / 3.0;

	bool perfectScore = false; 
	if (average==100)
	{
		perfectScore = true; 
	}

	cout << "Your average is " << average << '\n';
	
        if (perfectScore == true)
	{
		cout << "Congratulations! \n";
		cout << "That's a perfect score.\n";
		cout << "You deserve a pat on the back!\n";
                return 0; 
	}
	else
	{
		cout << "Sorry, you did not achive a perfect score.\n"; 
		return 0; 
	} 
}
Last edited on
Registered users can post here. Sign in or register to post.