counting the same type of info and return value.

Hi all

I am new to C++ and am having problem on some questions.
Please be patient with me and pardon me if I am not clear enough as I am very new to C++ and still trying hard to learn this new language.

First of all, I have created a struct for 6 existing records:



struct markRec
{
string studentPI; // eg B002
string name; // eg Anne Smith
float TT; // term test, eg 79.0
float FE; // final exams, eg 88.2
float score; // score (0.5 * TT + 0.5 * FE), eg 83.6
char grade; // grade, eg A
};

markRec markTable [30]; // array of not more than 30


I need to write three functions.
The first one is "enterRec". It will assigns the pas in values to the corresponding field of the record in markTable. The first parameter is an integer and is the Index used to index into the selected record of markTable. If the value of Index exceeds the maximum number permitted for markTable, a corresponding message will be displayed.

Here is my attempt:



bool enterRec(int Index, string studentPI, string name, float TT, float FE)
{
markTable[Index].studentPI = studentPI;
markTable[Index].name = name;
markTable[Index].TT = TT;
markTable[Index].FE = FE;

if(Index < 30)
{
return true;
}
else
{
return false;
}
}


My second function "countGrade" takes in the Grade (char) and finds the number of students that have this particular grade (there are grades A to F). This value will then be returned to the calling program. The function prototype I have to follow as: "int countGrade (char)"


I have tried 2 attempts:

first attempt:



int countGrade(char grade)
{
int Tgrades = 0;
char qGrade;

for (qGrade = 0; qGrade < grade; qGrade++)
{
switch(qGrade) // retrieve grade.
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
Tgrades ++;
}
}
return (Tgrades);
}


and my 2nd attempt for the same 2nd function:


int countGrade(char grade)
{
int Tgrades = 0;
Tgrades = (char) (markTable, markTable+30, qGrade);
return (Tgrades);
}


I am actually struggling for many hours just to do these. Would appreciate if anyone can enlighten me on my mistakes, with some advice and guidance.

Thank you very much.

Regards
billy
I think you're looping on the wrong thing. You should be looping through markTable array, checking whether that grade is equal to the one you're looking for, if it is increment Tgrades.
Topic archived. No new replies allowed.