sumlani
03-09-2008, 12:52 AM
I'm trying to get this program to show all the quiz scores and the average of the test scores. The program runs, but it will not show the average of the quiz scores. I keep getting a yellow arrow by the return avg....what is this? Here is my code:
[code]
#include <iostream>
#include <iomanip>
using namespace std;
double Avg(int [], int);
int main()
{
const int NUM_QUIZZES = 10;
int grade[NUM_QUIZZES];
int quiz;
double grade_avg;
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(1);
cout << "Please enter " << NUM_QUIZZES << "integer quiz grades."
<< endl << endl;
for (quiz = 0; quiz < NUM_QUIZZES; ++quiz)
{
cout << "\nEnter grade for guiz " << quiz + 1 << ": ";
cin >> grade[quiz];
}
grade_avg = Avg(grade,NUM_QUIZZES);
cout << endl;
cout << "the average quiz grade is " << grade_avg << endl;
return 0;
}
double Avg(int arr[], int size)
{
int i,
sum = 0;
double avg;
for (i = 0; i < size; ++i)
sum += arr[i];
avg = double(sum) / size;
return avg;
}
[code]
[code]
#include <iostream>
#include <iomanip>
using namespace std;
double Avg(int [], int);
int main()
{
const int NUM_QUIZZES = 10;
int grade[NUM_QUIZZES];
int quiz;
double grade_avg;
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(1);
cout << "Please enter " << NUM_QUIZZES << "integer quiz grades."
<< endl << endl;
for (quiz = 0; quiz < NUM_QUIZZES; ++quiz)
{
cout << "\nEnter grade for guiz " << quiz + 1 << ": ";
cin >> grade[quiz];
}
grade_avg = Avg(grade,NUM_QUIZZES);
cout << endl;
cout << "the average quiz grade is " << grade_avg << endl;
return 0;
}
double Avg(int arr[], int size)
{
int i,
sum = 0;
double avg;
for (i = 0; i < size; ++i)
sum += arr[i];
avg = double(sum) / size;
return avg;
}
[code]