Answer:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
int score1, score2 = 0;
double avg = 0;
cout<<"Enter student's name: ";
getline(cin, name);
cout<<"Enter the test score 1: ";
cin >> score1;
cout<<"Enter the test score 2: ";
cin >> score2;
if ((score1 >= 0 && score1 <= 100) && (score2 >= 0 && score2 <= 100)) {
avg = (score1 + score2) / 2.0;
cout << "Name: " << name << endl;
cout << "Test score 1: " << score1 << endl;
cout << "Test score 2: " << score2 << endl;
cout << "Average of the tests: " << avg << endl;
}
else {
cout << "Invalid input!" << endl;
}
return 0;
}
Step-by-step explanation:
Initialize the variables
Ask the user for the name and test scores
Check if the input is in the required range. If it is, calculate the average and print the name, test scores, and the average.
Otherwise, print an error message