### Type Error

I am having problems with the types in this program for out putting a letter grade. Lines 39-67, and line 148 give me this error. I am wondering if there is a different type that I should be assigning to these values. Thank you for your help.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158`` ``````#include #include #include #include #include using namespace std; //Declaring Constants const int ZERO = 0; const int ONE_HUNDRED = 100; double median = 0.00; double totalPoints; int size; vector scores; char letterGrade; double findMedian(vector &scores) { size_t mid = scores.size() / 2; if (scores.size() == 0) return 0.0; // change this to whatever it should be // Make scores[mid] the mid'th element nth_element(scores.begin(), scores.begin() + mid, scores.end()); if (scores.size() % 2 == 0) { // size is even. Need to average of scores[mid] and scores[mid-1] nth_element(scores.begin(), scores.begin() + mid - 1, scores.end()); median = (scores[mid] + scores[mid - 1]) / 2; } else { median = scores[mid]; } return median; } char DetermineScore(double totalPoints) { char grade; if (381 < totalPoints < 400) grade = "A"; else if (361 < totalPoints < 380) grade = "A-"; else if (341 < totalPoints < 360) grade = "B+"; else if (321 < totalPoints < 340) grade = "B"; else if (301 < totalPoints < 320) grade = "B-"; else if (281 < totalPoints < 300) grade = "C+"; else if (261 < totalPoints < 280) grade = "C"; else if (241 < totalPoints < 260) grade = "C-"; else if (221 < totalPoints < 240) grade = "D+"; else if (201 < totalPoints < 220) grade = "D"; else if (181 < totalPoints < 200) grade = "D-"; else if (180 < totalPoints < 180) grade = "F"; return grade; } int main() { int firstExam, secondExam, thirdExam; int error; cout << "Dr. DoLittle's Grading Program ..... (by Kirk Kelley)" << endl; do { error = 0; cout << "Please enter in the score for the first exam: "; cin >> firstExam; if (firstExam < 0 || firstExam > 100) { cout << "Please enter a valid score between 0 and 100" << endl; cin >> firstExam; cin.clear(); } } while (error); do { error = 0; cout << "Please enter in the score for the second exam: "; cin >> secondExam; if (secondExam < 0 || secondExam > 100) { cout << "Please enter a valid score between 0 and 100" << endl; cin >> secondExam; cin.clear(); } } while (error); do { error = 0; cout << "Please enter in the score for the third exam: "; cin >> thirdExam; if (thirdExam < 0 || thirdExam > 100) { cout << "Please enter a valid score between 0 and 100" << endl; cin >> thirdExam; cin.clear(); } } while (error); //declaring variable int homework; //initiating loop while (!cin.eof()) { homework = EOF; cout << "\nEnter score for homework assignment (press Ctrl+Z to quit): "; cin >> homework; if (!cin.good()) if (homework == EOF) break; else { cout << "\nInvalid Input. Entry must be an integer." << endl; cin.clear(); cin.ignore(std::numeric_limits ::max(), '\n'); } else { if (homework >= ZERO && homework <= ONE_HUNDRED) { scores.push_back(homework); } else { cout << "\nInvalid Input. Grade must be between 0-100." << endl; cin.clear(); cin.ignore(std::numeric_limits ::max(), '\n'); } } } letterGrade = DetermineScore; median = findMedian(scores); totalPoints = median + firstExam + secondExam + thirdExam; cout << "The total points earned was " << totalPoints << endl; cout << "The median homework score was " << median << endl; cout << "The letter calculated letter grade is " << letterGrade << endl; system("Pause"); return 0; } ``````
When you call a function, the function name must be followed by () parentheses. If the function expects one or more parameters, those should be placed within those parentheses. An example is at line 149,
 `` `` `` median = findMedian(scores);``

On the other hand, at line 148 there is this:
 `` `` `` letterGrade = DetermineScore;``
When the bare function name is used like that it does not cause the function to be called at all. Instead, the name on its own simply gives the address of the function.

I suggest you decide what value needs to be passed to `DetermineScore()` and change the code accordingly.
 ``123456789`` ``````if ( a < b < c ) // means same as if ( (a < b) < c ) // so in practise it evaluates to one of these: if ( true < c ) if ( false < c ) // perhaps if ( a < b && b < c )``````

Line 148: What are the types of:
 ``1234`` ``````letterGrade = DetermineScore; // well, char letterGrade; char DetermineScore(double);``````

You do have a function, but it does not look like you are calling a function.
char holds a single character - some of your letter grades have two characters (A-, B+ etc.)
Thank you for all the great advice! I am know running into another error that I cannot solve. My error reads binary '<<': no operator found which takes a right-hand operand of type "std::string'(or there is no acceptable conversion).

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157`` ``````#include #include #include #include #include using namespace std; //Declaring Constants const int ZERO = 0; const int ONE_HUNDRED = 100; double median = 0.00; double totalPoints; int size; vector scores; string grade; double findMedian(vector &scores) { size_t mid = scores.size() / 2; if (scores.size() == 0) return 0.0; // change this to whatever it should be // Make scores[mid] the mid'th element nth_element(scores.begin(), scores.begin() + mid, scores.end()); if (scores.size() % 2 == 0) { // size is even. Need to average of scores[mid] and scores[mid-1] nth_element(scores.begin(), scores.begin() + mid - 1, scores.end()); median = (scores[mid] + scores[mid - 1]) / 2; } else { median = scores[mid]; } return median; } string determineScore(double totalPoints) { if (totalPoints >= 381 && totalPoints <= 400) grade = "A"; else if (totalPoints >= 361 && totalPoints <= 380) grade = "A-"; else if (totalPoints >= 341 && totalPoints <= 360) grade = "B+"; else if (totalPoints >= 321 && totalPoints <= 340) grade = "B"; else if (totalPoints >= 301 && totalPoints <= 320) grade = "B-"; else if (totalPoints >= 281 && totalPoints <= 300) grade = "C+"; else if (totalPoints >= 261 && totalPoints <= 280) grade = "C"; else if (totalPoints >= 241 && totalPoints <= 260) grade = "C-"; else if (totalPoints >= 221 && totalPoints <= 240) grade = "D+"; else if (totalPoints >= 201 && totalPoints <= 220) grade = "D"; else if (totalPoints >= 181 && totalPoints <= 200) grade = "D-"; else if (totalPoints >= 180) grade = "F"; return grade; } int main() { int firstExam, secondExam, thirdExam; int error; cout << "Dr. DoLittle's Grading Program ..... (by Kirk Kelley)" << endl; do { error = 0; cout << "Please enter in the score for the first exam: "; cin >> firstExam; if (firstExam < 0 || firstExam > 100) { cout << "Please enter a valid score between 0 and 100" << endl; cin >> firstExam; cin.clear(); } } while (error); do { error = 0; cout << "Please enter in the score for the second exam: "; cin >> secondExam; if (secondExam < 0 || secondExam > 100) { cout << "Please enter a valid score between 0 and 100" << endl; cin >> secondExam; cin.clear(); } } while (error); do { error = 0; cout << "Please enter in the score for the third exam: "; cin >> thirdExam; if (thirdExam < 0 || thirdExam > 100) { cout << "Please enter a valid score between 0 and 100" << endl; cin >> thirdExam; cin.clear(); } } while (error); //declaring variable int homework; //initiating loop while (!cin.eof()) { homework = EOF; cout << "\nEnter score for homework assignment (press Ctrl+Z to quit): "; cin >> homework; if (!cin.good()) if (homework == EOF) break; else { cout << "\nInvalid Input. Entry must be an integer." << endl; cin.clear(); cin.ignore(std::numeric_limits ::max(), '\n'); } else { if (homework >= ZERO && homework <= ONE_HUNDRED) { scores.push_back(homework); } else { cout << "\nInvalid Input. Grade must be between 0-100." << endl; cin.clear(); cin.ignore(std::numeric_limits ::max(), '\n'); } } } grade = determineScore(totalPoints); median = findMedian(scores); totalPoints = median + firstExam + secondExam + thirdExam; cout << "The total points earned was " << totalPoints << endl; cout << "The median homework score was " << median << endl; cout << "The letter calculated letter grade is " << grade << endl; system("Pause"); return 0; } ``````
On line 153 is the error, on the word "<< grade".
You're sending totalPoints to the determineScore function on line 147, but you don't actually calculate totalPoints until line 149. You're sending some uninitialized value to the function.
The `#include <string> ` seems to be missing.
Thank you! that totally works now.
Topic archived. No new replies allowed.