I'm experiencing an unexpected result in my code. This program allows the user to input their points earned on an assignment, and the program is supposed to calculate the user's average, letter grade, and GPA. Unfortunately after the average has been computed the result is always 'inf' instead of the desired value, and the letter grade and average are always 'A' and '4.0'. I believe the problem is in the computeAverage function but I'm not entirely sure. I've played around with the code for a few hours and searched for a solution to this problem but alas, my google-fu has failed me. Does anyone have any ideas on how to resolve this issue? Thanks in advance.
Thank you jonnin, that resolved the the problem. However, now letter grade and GPA always result if 'F' and '0.00' no matter what the average is. Any advice?
edit: nevermind, I was able to resolve the issue on my own. Thank you again for your help, I greatly appreciate it.
class Grader
{
public:
// ...
double computeAverage(double pointsEarned, double pointsPossible)
{
// GNU: **warning** suggest parentheses around assignment used as truth value
// LLVM: **warning** using the result of an assignment as a condition without parentheses
// note: use '==' to turn this assignment into an equality comparison
// Microsoft: **warning** Incorrect operator: assignment of constant in Boolean context. Consider using '==' instead.
if (pointsPossible = 0)
{
return 0;
}
else
{
return pointsEarned / pointsPossible;
}
}
// ...
};
This is the first I've heard of compiling with warnings enabled. Those error messages are much easier to understand than what I've been getting in powershell.
g++ or clang++: compile with -std=c++14 -Wall -Wextra -pedantic-errors
microsoft: compile with -std:c++14 -W4 -analyze, add -permissive- if the version is current