#include #include //include this if you want string variables #include //include if you want to do file IO using namespace std; // Write a program that takes 3 grades in, and // outputs the letter grade based on the average score. // Also, for fun, ask for their name so you can use it later int main() { //step 0: Declare some variables double grade1; double grade2; double grade3; double average; char letterGrade; //A variable for storing a single character string name; //string variables store words (i.e. string of characters) ifstream infile("gradeBook.txt"); //a variable to read data from a file ofstream outfile("letterGrades.txt"); //a variable to write data to a file //Replace the cin and cout statements with infile and outfile to do File IO. //Step 1: Greet user, tell them what the program is going to do cout << "Hello, we are going to calculate your grade! (from your 3 exam scores)" << endl; //Step 1.5: Ask for user's name, store in a variable //cout << "What's your name? " << endl; infile >> name; //Step 2: Ask user to enter 3 exam scores, store in 3 variables //cout << "Enter 3 exam scores!: " << endl; infile >> grade1; infile >> grade2; infile >> grade3; //Step 3: Calculate average score average = (grade1 + grade2 + grade3) / 3; //Step 4: Determine letter grade if (average >= 90) { //an A! letterGrade = 'A'; } else if (average >= 80) { //a B letterGrade = 'B'; } else if (average >= 70) { //C letterGrade = 'C'; } else { //F letterGrade = 'F'; } //Step 5: output the letter grade, use their name outfile << "Thank you" << name << endl; outfile << "Your letter grade is: " << letterGrade << endl; return 0; }