PDA

View Full Version : Help pls!!


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]

yawningdog
03-10-2008, 10:11 AM
What variable type is sum? I don't see it declared anywhere. Are you typecasting it as a double in function Avg?

It compiles and runs fine in VS and g++, but I don't see how.

DarkOwnagePeace
03-12-2008, 09:01 PM
Kinda silly to ask but most compilers require you to use system("pause") or (i like to use getch())
is this the case? or does your command prompt pop up for you to enter everything? and nothing comes out? or it comes out wrong?
figure i'd start off with the obvious, but as you havn't responded in days i'll assume you fixed it :)

sumlani
03-15-2008, 08:24 PM
When I complied it at the first return it worked fine.