fix the error below #include <iostream> #include <string> using namespace std; i
ID: 640265 • Letter: F
Question
fix the error below
#include <iostream>
#include <string>
using namespace std;
int main()
{
int score1, score2, score3;
double average;
string name;
cout << "Enter your full name: " ;
cin >> name;
cout << "Enter the test scores for Midterm 1, Midterm 2, and the Final: ";
cin >> score1 >> score2 >> score3;
// Calculate and display the average score
average = (score1 + score2 + score3) / 4.0;
cout << "Displaying the scores for " << name << endl;
cout << setw(13) << "Midterm 1: " << setw(5) << score1 << endl;
cout << setw(13) << "Midterm 2: " << setw(5) << score2 << endl;
cout << setw(13) << "Final: " << setw(5) << score3 << endl;
cout << "=========================" << endl;
cout << setw(13) << fixed << showpoint << setprecision(2) << "Average: "
<< setw(5) << average << endl;
// If the average is 90 or higer, congratulate the user and display that it's an A
if Average >= 90
cout << " Congratulations! ";
cout << "You have an A ";
return 0;
}
Explanation / Answer
//include iomanip header file in order to use setw.
//changes in IF -- Average to average and use braces
#include <iostream>
#include <string>
#include <iomanip> //include iomanip header file in order to use setw.
using namespace std;
int main()
{
int score1, score2, score3;
double average;
string name;
cout << "Enter your full name: " ;
cin >> name;
cout << "Enter the test scores for Midterm 1, Midterm 2, and the Final: ";
cin >> score1 >> score2 >> score3;
// Calculate and display the average score
average = (score1 + score2 + score3) / 4.0;
cout << "Displaying the scores for " << name << endl;
cout << setw(13) << "Midterm 1: " << setw(5) << score1 << endl;
cout << setw(13) << "Midterm 2: " << setw(5) << score2 << endl;
cout << setw(13) << "Final: " << setw(5) << score3 << endl;
cout << "=========================" << endl;
cout << setw(13) << fixed << showpoint << setprecision(2) << "Average: "
<< setw(5) << average << endl;
// If the average is 90 or higer, congratulate the user and display that it's an A
if(average >= 90) // CHANGE Average to average and use braces
{
cout << " Congratulations! ";
cout << "You have an A ";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.