Write a C++ program that will ask the user to input his/her full name. Then, ask
ID: 3589490 • Letter: W
Question
Write a C++ program that will ask the user to input his/her full name. Then, ask for four test scores. The program should then calculate the average of the four scores. If the average is 90 or higher, the program should display the message: "Congratulations FULL NAME, you have an excellent score!". If the average is less than 90 but over 70, the program should display the message: "FULL NAME, you are passing the class". Otherwise, if the average is under 70, display the message "FULL NAME, you are not passing the class".
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
string name;
int scores[4];
cout<<"Enter the full name: "<<endl;
getline(cin, name);
cout<<"Enter the four test scores: "<<endl;
for(int i=0;i<4;i++) {
cin >> scores[i];
}
int sum = 0;
for(int i=0;i<4;i++) {
sum+=scores[i];
}
double average = sum/(double)4;
if(average >= 90) {
cout<<"Congratulations "<<name<<", you have an excellent score"<<endl;
} else if (average >=70 && average < 90) {
cout<<name<<", you are passing the class"<<endl;
} else {
cout<<name<<", you are not passing the class"<<endl;
}
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.