[email protected] wrote:
> I need to figure out what is wrong with this. I need the average of 
> the scores to be calculated in the AverageGrade function, but I am 
> having problems. Can someone help me?
> 
> float AverageGrade(Student studentGrade, int average)
> {
> int i;
> float n;
> float AveSco = 0.0;
> bool validString = true;
> 
> for(i=0;i<n;i++)
> {
> AveSco = AveSco + n;
> };
> AveSco = AveSco / n;
> cout << "The average student grade is: " << AveSco << endl; 
> return AverageGrade;
> };
>

You have a variable 'n' in main() that you set to the number of students 
via operator input (cin).

You have another variable 'n' in your AverageGrade function that has the 
same name but it is not the same variable and you do not initialize it in 
any way.  It's value is undefined.  Perhaps what you want to do is make 'n' 
or 'number_of_students' and argument that is passed in to the AverageGrade 
function.  Also it's type should be int not float.

You have a 'for' loop in AverageGrade that is intended to calculate the sum
of the scores for all students and you are keeping this sum in AveSco.  Just
to make thinks clearer, create a new float parameter called sum_of_all_scores
and use it in your 'for' loop after initializing it to zero.  During each pass 
thru your 'for' loop you need to increment sum_of_all_scores by the current 
students score.

After you are done with the loop calculate the average score using the sum and
the number of students.



------------------------------------

To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.Yahoo! 
Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/c-prog/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/c-prog/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to