### grade average calculator issues

This program only compiles if the number of grades has already been predetermined, but not if the number is a value declared by the user (which varies each time the program is run).

Instructions:
Write a program that will read in grades, the number of which is
also input by the user. The program will find the sum of those grades and
pass it, along with the number of grades, to a function which has a “pass
by reference” parameter that will contain the numeric average of those
grades as processed by the function. The main function will then determine
the letter grade of that average based on a 10-point scale.

Code:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586`` ``````#include #include #include #include using namespace std; void getNum(int &); void calculateaverage(double &); char calculategrade(double); int main() { int value; double avg=0; getNum(value); calculateaverage(avg); calculategrade(avg); cout<>userNum; } void calculateaverage(double &avg) { int score; for(int i=0;i>score; avg+=score; } avg/=userNum; cout<60 && myAvg<70) return 'D'; else if (myAvg>70 && myAvg<80) return 'C'; else if(myAvg>80 &&myAvg<90) return 'B'; else return 'A'; }``````
Line 41, userNum is not declared there.i suggest you return it and use it there.So it will give you a compilation error there.Thats the problem.
I would suggest that you make you void calculateaverage(double &avg) accepts two arguments. one for the length also
Try this

#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>

using namespace std;

int getNum(int &);
void calculateaverage(double &, int);
char calculategrade(double);
int main()

{
int n;
int value;
double avg=0;
getNum(value);
calculateaverage(avg, value);
calculategrade(avg);
cout<<calculategrade(avg)<<endl;

system("pause");

}

int getNum(int &userNum)

{

cout<<"Enter number of grades:";

cin>>userNum;

}

void calculateaverage(double &avg, int userNum)

{
int score;
for(int i=0;i<userNum;i++)

{
cout<<"Enter numeric grade between 0-100:";
cin>>score;
avg+=score;
}

avg/=userNum;

cout<<avg<<endl;

}
char calculategrade(double myAvg)

{

if(myAvg<60)

return 'F';

else

if(myAvg >60 && myAvg<70)

return 'D';

else

if (myAvg>70 && myAvg<80)

return 'C';

else

if(myAvg>80 &&myAvg<90)

return 'B';

else

return 'A';

}
Topic archived. No new replies allowed.