int main()
{
string firstNameFromUser;
string lastNameFromUser;
float userGrades;
float userAvg;
//Initalize the sum of the grades and the counter to zero
float sumofGrades = 0;//Sum of the grades
int numberofGrades = 0;//Grade counter
//Output file stream
ofstream userNameandAvg;
system("cls");//Preforms a system call to cls and clears the screen
cout << "Please enter your first and last name: " << endl;//Prompts the user to enter their first and last name
cin >> firstNameFromUser >> lastNameFromUser;//Reads in the first and last name from user and stores them in their respective string variables
cout << "Please enter your grades and press q to quit: " << endl;//Prompts user to enter their grades
cin >> userGrades;//Takes in the grades from user and stores them in the float variable
while (userGrades)
{
while (userGrades < 0)
{
cout << "The last number you entered is negative. Please enter a positive number: " << endl;//If the user enters a negative number, prompts the user to enter a positive number
cin >> userGrades;//Takes in the grades from user and stores them in the float variable
}
if (userGrades >= 0)
{
sumofGrades = sumofGrades + userGrades;
numberofGrades++;
cin >> userGrades;
}
}
userAvg = sumofGrades / numberofGrades;//Calculates the user's average grade
//Open output file stream
userNameandAvg.open("ee261_grade.txt");//Creates and stores the grade report in ee261_grade.txt
userNameandAvg << firstNameFromUser << " " << lastNameFromUser << ", " << "your average grade is: " << userAvg << "%" << endl;//Prints the user's name and average grade in ee261_grade.txt
//Close output file stream
userNameandAvg.close();