#include <iostream>
using namespace std;
int main()
{
string name; //to store name
int age; //to store age
int scores[4]; // to store scores of 4 exams
//user input ffor name
cout<<"Please enter your name: ";
cin >> name;
//user input for age
cout << name << ", how old are you? ";
cin >> age;
//user input for scores
cout << "Please enter your scores in 4 exams : ";
for(int i = 0; i < 4; i++)
cin >> scores[i];
double total = 0; //to store total scores
double average; //to store average
//calculating total
for(int i = 0; i < 4; i++)
total += scores[i];
//calculating average
average = total / 4;
//prints appropriate output
cout << endl << "Dear " << name << endl;
cout << "At age " << age << " with scores ";
for(int i = 0; i<4; i++)
{
if(i != 3)
cout << scores[i] << ", ";
else
cout << "and " <<scores[i] << " is " << average << endl;
}
cout << "Your advisor";
return 0;
}
Please refer to the screenshot of the code to understand the indentation of the code.
Sample Output :
Get Answers For Free
Most questions answered within 1 hours.