Program just exits after first user input

Here's what I have to do:

a) Prompt the user to enter numerical grades of students in a test, one at a time, and store it in an array. This is accomplished in the main module. The user enters a negative number to indicate all the grades are entered. The program will keep the count of the number of grades entered.

b) Call function to calculate the average grade of the class, the median, and the lowest and highest grades.

c) Finally display the class average, highest grade, the lowest grade, and the median at the bottom. At the end the user is prompted to exit or enter grades for another class.

And here's my program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

const int STUDENT = 300;
float gradecalc(float grade[STUDENT]), grade[STUDENT], avg, high, low, med;
int i, j, temp;
char ans;

int main(float avg, float high, float low, float med)
{
	for(i = 0; i < STUDENT; i ++)
	{
		cout << "Please enter grade: ";
		cin  >> grade[i];

		for ( i = 0; i < (STUDENT - 1); i++)
		{
			for(j = 1; j < STUDENT; j++)
			{
				if (grade[j] < grade[j-1])
				{
					temp = grade[j];
					grade[j] = grade[j-1];
					grade[j-1] = temp;
				}
			}

			if ( grade[i] < 0)
			{
				cout << "\nNumber           Grade"
					 << "\n-------         -------"
					 << endl;
				cout << setw(2) << i
					 << setw(9) << grade[i];
	  
				avg = gradecalc(grade);
				high = gradecalc(grade);
				low = gradecalc(grade);
				med = gradecalc(grade);

				cout << "\n\nMedian Grade: " << med
					 <<	"\nLowest Grade: "	<< low
					 <<	"\nThe class average: " << avg
					 <<	"\nHighest Grade is: " << high;

				cout << "\n\nWould you like to start a new class?"
					 << "\n('Y' or 'N'): ";
				cin  >> ans;

				if(ans == 'Y' || ans == 'y')
				{
					continue;
				}
				else
				{
					break;
				}
			}
			else
			{
				continue;
			}
		}
	}

	return 0;
}

float gradecalc(float grade[STUDENT])
{
	float sum;
	sum = 0;
	high = grade[0];
	low = grade[0];

	for(i = 0; i >= 0 && i < STUDENT; i ++)
		sum = sum + grade[i];
		avg = sum / i++;
		high = grade[i];
		low = grade[0];

	if(i % 2 == 0)
		med = grade[i/2];
	else
		med = (grade[i/2] + grade[i/2 + 1])/2;

	return avg, high, low, med;
}



So where did I go wrong first? I'm lost.
Last edited on
gah.

Global variables.

Not the global variables...
Go easy on me...I'm just a beginner. So when I changed some of the variables to local, I got an error message "error C2082: redefinition of formal parameter." What do I need to do to make this work??? It's due tonight at midnight CST and I'm so frustrated. Any help would be much appreciated!
First of all can you please use code tags [ Code] [ /Code] around everything so that it indents correctly. It's very hard to see what's happening with all the braces on the left side.
Ok I fixed it. Sorry. Not sure if you can tell, but I have no idea how bubbleSort works(lines 19-29). I'd like to learn though.
Last edited on
Topic archived. No new replies allowed.