### Program outputting wrong result

Ok, so I just started with c++ a few days ago, and I tried to make a GPA Calculator. I see nothing wrong with the code, but when I tested it out, I always receive an incorrect answer. I just put 'A' for every letter grade, and 4 for every credit hour so that I knew the GPA should be 4.0, but for some reason it gives me 65 for the GPA. Here is the code:

//GPA Calculator

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int qualitypoints(char letter){
int qPoints;
if (letter == 'A')
qPoints = 4;
else if (letter == 'B')
qPoints = 3;
else if (letter == 'C')
qPoints = 2;
else if (letter == 'D')
qPoints = 1;
else
qPoints = 0;
return qPoints;
}

{
string course;
char letter;
int hours;

};

int main()
{

float GPA;

float totalqp;

cout << "Enter the letter grade of your first course " << endl;

cout << "Enter the name of your first course " << endl;

cout << "Enter the number of hours your course was " << endl;

cout << "Enter the letter grade of your second course " << endl;

cout << "Enter the name of your second course " << endl;

cout << "Enter the number of hours your course was " << endl;

cout << "Enter the letter grade of your third course " << endl;

cout << "Enter the name of your third course " << endl;

cout << "Enter the number of hours your course was " << endl;

cout << "Enter the letter grade of your fourth course " << endl;

cout << "Enter the name of your fourth course " << endl;

cout << "Enter the number of hours your course was " << endl;

cout << "Enter the letter grade of your fifth course " << endl;

cout << "Enter the name of your fifth course " << endl;

cout << "Enter the number of hours your course was " << endl;

cout << "Your GPA is: " << GPA << endl;

system("PAUSE");
return 0;
}

Maybe use your qualitypoints function to give you a numerical value for the grade? Also make sure you are inputting 'A' and not 'a'.
First, I'd like to thank you for your response. Sorry, I'm very new to the forum, and don't know what code tags even are. I put capital A each time, so that's not the issue. And, what do you mean by give a numerical value for the grade? It already does. If it didn't give a numerical value, I wouldn't get a number (65).
Also I see the function qualitypoint() is unused.
You will see an Edit button, then click it. You'll see a format menu on the right, then click <>, then wrap your code between two tabs you've just received.
Can you explain what you mean by "unused"? Sorry, I'm very nooby.
You defined a function (E.g qualitypoint()) but please, check the function main(), you haven't used this yet.
You are not calling the function qualitypoints() - C++ will use the ASCII value of a letter ('A' = 65, 'B' = 66 and so on) Google ASCII values

 ``123`` `````` totalqp = (grade1.hours * qualitypoints(grade1.letter)) + (grade2.hours * qualitypoints(grade2.letter)) + (grade3.hours * qualitypoints(grade3.letter)) + (grade4.hours * qualitypoints(grade4.letter)) + (grade5.hours * qualitypoints(grade5.letter)); ``````

You have to call the function. Does that help?
Ahh, I see. Thanks a lot, now I am getting the right answers.
Topic archived. No new replies allowed.