Question

1 // This program averages 3 test scores. 2 // It uses the variable perfectScore as...

1 // This program averages 3 test scores.
2 // It uses the variable perfectScore as a flag.
3 include <iostream>
4 using namespace std;
5
6 int main()
7 {
8      cout << "Enter your 3 test scores and I will ";
9           << "average them:";
10     int score1, score2, score3,
11     cin >> score1 >> score2 >> score3;
12     double average;
13     average = (score1 + score2 + score3) / 3.0;
14     if (average = 100);
15          perfectScore = true; // Set the flag variable
16     cut << "Your average is " << average
17         >> endl;
18     bool perfectScore;
19     if (perfectScore);
20     {
21         cout << "Congratulations!\n";
22         cout << "That's a perfect score.\n";
23         cout << "You deserve a pat on the back!\n";
24     return 0;
25 }
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

The correct code is :


# include <iostream>
using namespace std;

int main()
{
      cout << "Enter your 3 test scores and I will average them:";
     int score1, score2, score3;
     bool perfectScore=false;
     cin >> score1 >> score2 >> score3;
     int average;
     average = (score1 + score2 + score3) / 3;
     if (average== 100)
        perfectScore = true; // Set the flag variable
    cout << "Your average is " << average<< endl;
   
     if (perfectScore)
     {
         cout << "Congratulations!\n";
         cout << "That's a perfect score.\n";
         cout << "You deserve a pat on the back!\n";
     }
return 0;
}

Explanation:

there has to be semicolon after declaring score1,score2,score3; and 8 and 9 has to be in a single line.we should convert average variable to int because we are comparing with 100. and we should remove semi colon after if conditions.We should declare all the variables before we are using them. If we do not assign any value to them,randomly they will take any value as a default value.so by default perfect score variable is false.

code:

Note:If you have any queries...please comment...Thank you..

Add a comment
Know the answer?
Add Answer to:
1 // This program averages 3 test scores. 2 // It uses the variable perfectScore as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT