In this problem, you will be prompting a student for grades and credits for courses taken. From that, you will calculate a GPA.
This site:
http://www.back2college.com/gpa.htm shows you how to calculate a GPA.
Keep prompting the student if they want to add more courses.
IMPORTANT NOTES!
The course name is prompted for, but nothing is done with it.
We are just using the grades A, B, C, D, and F so you won't have to do so much typing!
You will need to use the "set precision" command as shown in the book. Set it to "fixed" and "2".
You will need to use the "cin.ignore()" function as discussed earlier in the course.
Here is a sample run:
Enter a course name: CMPSC 101
Enter number of credits: 3
Enter your grade (A, B, C, D, F): A
Continue ('Yes' or 'No')? Yes
Enter a course name: BIO 100
Enter number of credits: 3
Enter your grade (A, B, C, D, F): B
Continue ('Yes' or 'No')? Yes
Enter a course name: ACCT 50
Enter number of credits: 1
Enter your grade (A, B, C, D, F): D
Continue ('Yes' or 'No')? No
Total grade points: 22
Total credits attempted: 7
Your GPA is 3.14
//So far what is done
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main () {
cout<<std::fixed<<std::setprecision(2);
string grade;
string name;
string answer="Yes";
int totalcredits;
int gradepoints=0;
int credits=0;
double GPA;
while (answer=="Yes"){
cout<< "Enter a course name: " ;
getline(cin,name);
cout<<name;
cout<<endl;
cout<< "Enter number of credits: ";
cin >> credits;
cout << credits << endl;
cout<< "Enter your grade (A, B, C, D, F): ";
cin >> grade;
cout <<grade << endl;
cout<< "Continue ('Yes' or 'No')? ";
cin >> answer;
cin.ignore();
cout << answer << endl;
}
cout<<"Total grade points: ";
cout<< endl;
cout<<"Total credits attempted: ";
cout<<endl;
cout<<"Your GPA is ";
cout<< endl;
if (grade == "A") {
gradePoints = 4 + credits //<-- what do I do here for credits?? * 4.00;
}
if (grade == "B") {
gradePoints = 3 + credits * 4.00;
}
if (grade == "C") {
gradePoints = 2 + credits * 4.00;
}
if (grade == "D") {
gradePoints = 1 + credits * 4.00;
}
if (grade == "F") {
gradePoints = 0 + credits * 4.00;
}
return 0;
}