PDA

View Full Version : help with arrays


sumlani
02-23-2008, 12:38 PM
I'm trying to get this program to print the minimum and maximum grades as well as the average of the quizzes. I know I haven't put any code in for the minimum yet, just trying to get it to compile!!!!




#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
cont int Num_Quizzes = 10;
cont in Min_Grade = 85;
int grade[Num_Quizzes];
int quiz;
grade_sum = 0;
double grade_avg;
cout << setprecision(1)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint);
cout << "Please enter " << Num_Quizzes
<< "interger quiz grades." << endl << endl;
for (quiz = 0; quiz < Num_Quizzes; ++quiz)
{
cout << endl;
cout << "Enter grade for quiz " << quiz + 1 << ":";
}
cout << endl;
cout << "The grades you entered are:";
for (quiz = 0; quiz < Num_Quizzes; ++quiz)
cout << setw(5) << grade[quiz];
for (quiz = 0; quiz < Num_Quizzes; ++quiz)
grade_sum += grade[quiz];
grade_avg = double(grade_sum) / Num_Quizzes;
cout << endl << endl;
cout << "The average quiz grade is " << grade_avg << endl;
return 0;
for (quiz = 0; quiz < Num_Quizzes; ++quiz)
if (grade[quiz] >= Min_Grade)
{
cout << endl:
cout << "The first grade of at least " << Min_Grade
<< " is:" << endl << endl;
cout << "Quiz #" <<quiz +1 << " Grade: "
<< setw(3) << grade[quiz] << endl;
break;
}
if (quiz >= Num_Quizzes)
{
cout << endl;
cout << "No grade greater than " << Min_Grade
<< " was found." << endl;
}
return 0;
}

sumlani
02-23-2008, 05:20 PM
I've gotten most of this to compile, but it stops on the average. The Min_grade isn't even being read. I'm trying to figure out what I may need to get this to run properly. I've fixed errors such as cont.....to const. Basically it stops after the first return 0;

yawningdog
02-25-2008, 11:53 AM
line 12 - You haven't declared a type. Should be something like int grade_sum = 0;
line 36 should end in a semicoloncout << endl;
Once I fixed these it compiled and ran, but still has lots of issues. Post back again if you get stuck.

Oh yeah, and I deleted the first return 0; There should only be one of those per declaration of main().