string grade1,grade2,grade3,grade4 and/or double value1,value2,value3,value4within the function again.
if (grade == grade2) value = value2; if (grade == grade3) value = value3; if (grade == grade4) value = value4;
sum = sum + value;
counter = counter + 1;
if (grade == "Z")
cout << "No grades entered";
else
cout << sum/counter ;
(this is wrong because,grade will always be equal to "Z" when the loop terminates.Hence,the else part will never be executed.)
average = sum/value;
or
average = sum/grade;
instead of
average = sum/counter;
Note : No points have been cut off for not intializing the variables or intializing them with incorrect values.Though you are supposed to do that,since there was no comment in the code asking you to initialize the variables,you were not penalized for that mistake.