Loops and Grades Chapter 7 stretch C++ HELP PLEASE

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;
}
Last edited on
Do you have a question?
please use code tags and put your question at the top, not hidden in comments in the code.
presumably, if its 'normal', your credits are the # of hours of the course.
and your gpa is a weighted average.
so if you had a class grade B with 3 hours and a class with grade C with 1 hour and a class with A for 4 hours, you have (4*4+ 3*3 + 2*1)/8 = gpa where (4 hours * 4 for a, 3 hours * 3 for b, c is 2 and 1 hour, all over the total # hours...)

that is the normal way of doing it, does your assignment specify how to compute it or did they assume you knew this? you are doing the computation weird, its just grade's value * credit value, and gpa is over total credit value.
Last edited on
Topic archived. No new replies allowed.