چرا برنامه من max را خطا میدهد؟
چکار کنم برنامه درست بشه؟؟؟

// Project1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
float classes[5][5];
float max = 0;

void menu();
int main();

void sort_AtoD(float(&array)[5][5]);

bool getGrades(void){

int c;
int j;
int i;
bool selected[5] = { false, false, false, false, false };

for (j = 0; j < 5; j++){
system("cls");
cout << "Enter The Desired Class:\n";
cin >> c;


c--;
if (c >= 0 && c <= 4 && selected[c] == false){
system("cls");

float num;
for (i = 0; i < 5; i++){
cout << "Student" << i + 1 << ": ";
cin >> num;
cout << "\n";
if (num >= 0 && num <= 20)
classes[c][i] = num;
else{
cout << "Error!!!\n";
system("pause");
i--;
}
}


}
else{
cout << "Eroor!!!\n";
system("pause");
j--;
continue;
}
selected[c] = true;

char end = NULL;
cout << "if End:press 'e' & if Continue:press any key:";
cin >> end;
if (end == 'e')
break;
else
continue;

}
return true;
}
//*********************************************
bool sort_AtoD(int c){
int i, j;
float temp;
bool index[5] = {};
for (i = 0; i < 5; i++){
for (j = 0; j < 5; j++){
if (classes[c][j] > max && index[j]==false) {
max = classes[c][j];
index[j] == true;
}
}
cout << max<<"\n";
}
/*cout << "Class " << c << "\n";
for (int j = 0; j < 5; j++){
cout << "Student " << j + 1 << " = " << a[j] << "\n";
}*/
char ch;
cout << "return to menu(Y/N)\n";
cin >> ch;
if (ch == 'y')
menu();
else{
system("cls");
return 0;
}
}
//******************************************
bool sort_DtoA(int c){
float temp;
for (int i = 0; i < 5; i++){
for (int j = 1; j < 5; j++){
if (classes[c][i]>classes[c][j]){
temp = classes[c][i];
classes[c][i] = classes[c][j];
classes[c][j] = temp;
}
}
}
cout << "Class " << c << "\n";
for (int j = 0; j < 5; j++){
cout << "Student " << j + 1 << " = " << classes[c - 1][j] << "\n";
}
char c;
cout << "return to menu(Y/N)\n";
cin >> c;
if (c == 'y')
menu();
else{
system("cls");
return 0;
}
}
//******************************************
void sort(){
char s;
system("cls");
cout << "a.Ascending to Descending\n";
cout << "b.Descending to Ascending\n";
cout << "c.Back\n";
cin >> s;

switch (s){
case 'a':
int c;
system("cls");
cout << "Please Select Class for Sort:\t";
cin >> c;
sort_AtoD(c);
break;
case 'b':
int b;
system("cls");
cout << "Please Select Class for Sort:\t";
cin >> c;
sort_DtoA(c);
break;
case 'c':
system("cls");
menu();
break;
default:
cout << "Invalid!";
system("cls");
sort();
break;
}
}
//******************************************
int avrage_AtoD(){
system("cls");
int i;
int h;
//float avgs[5];


for (i = 0; i < 5; i++){
float avg = 0;
for (h = 0; h < 5; h++){
avg += classes[i][h];
}
//avgs[i] = avg;
cout << "Class:" << i + 1 << "\n"
<< "\tstu1=" << classes[i][0]
<< "\tstu2=" << classes[i][1]
<< "\tstu3=" << classes[i][2]
<< "\tstu4=" << classes[i][3]
<< "\tstu5=" << classes[i][4]
<< "\tAvrage=" << avg / 5 << "\n";
}

/* bool selected[5] = { false, false, false, false, false};
float max = 0;
int index[5];
for (h = 0; h < 5; h++){
for (i = 0; i < 5; i++){
if (selected[i] == false){
if (avgs[i]>max){
max = avgs[i];
index[h] = i;
selected[i] == true;
}
}
else{
continue;
}
}
}*/

char c;
cout << "return to menu(Y/N)\n";
cin >> c;
if (c == 'y')
menu();
else
return 0;
}

//******************************************
int avrage_DtoA(){
system("cls");
int i;
int h;

for (i = 0; i < 5; i++){
float avg = 0;
for (h = 0; h < 5; h++){
avg += classes[i][h];
}

cout << "Class:" << i + 1 << "\n"
<< "\tstu1=" << classes[i][0]
<< "\tstu2=" << classes[i][1]
<< "\tstu3=" << classes[i][2]
<< "\tstu4=" << classes[i][3]
<< "\tstu5=" << classes[i][4]
<< "\tAvrage=" << avg / 5 << "\n";
}
char c;
cout << "return to menu(Y/N)\n";
cin >> c;
if (c == 'y')
menu();
else
return 0;
}
//******************************************
bool avrage(){
char s;
system("cls");
cout << "a.Ascending to Descending\n";
cout << "b.Descending to Ascending\n";
cout << "c.Back\n";
cin >> s;

switch (s){
case 'a': avrage_AtoD();
break;
case 'b': avrage_DtoA();
break;
case 'c':
system("cls");
menu();
break;
default:
cout << "Invalid!";
system("cls");
sort();
break;
}
return true;
}
//******************************************
bool print(){
system("cls");
int i;
int h;
for (i = 0; i < 5; i++){
for (h = 0; h < 5; h++){
}

cout << "Class:" << i + 1 << "\n"
<< "\tstu1=" << classes[i][0]
<< "\tstu2=" << classes[i][1]
<< "\tstu3=" << classes[i][2]
<< "\tstu4=" << classes[i][3]
<< "\tstu5=" << classes[i][4]
<< "\n";
}
char c;
cout << "return to menu(Y/N)\n";
cin >> c;
if (c == 'y')
menu();
else
return 0;
return true;
}
//********************************************
int search_class(){
system("cls");
int i;
cout << "Select Number Class:\t";
cin >> i;
cout << "Class " << i << "\n";
for (int j = 0; j < 5; j++){
cout << "Student " << j + 1 << " = " << classes[i - 1][j] << "\n";
}
char c;
cout << "return to menu(Y/N)\n";
cin >> c;
if (c == 'y')
menu();
else
return 0;
}
//********************************************
int search_stu(){
system("cls");
int i;
int s;
cout << "Select Number Class:\t";
cin >> i;
cout << "\n";
cout << "Select Number Student:\t";
cin >> s;
cout << "\n";
cout << "Student " << s << " From Class " << i << " = " << classes[i - 1][s - 1] << "\n";
char c;
cout << "return to menu(Y/N)\n";
cin >> c;
if (c == 'y')
menu();
else
return 0;
}
//********************************************
bool search(){
system("cls");
char c;
cout << "a.Search Based on Class\n";
cout << "b.Search Based on Student\n";
cout << "c.Back\n";
cin >> c;

switch (c){
case'a': search_class();
break;
case'b':search_stu();
break;
case'c':
system("cls");
menu();
break;
default:cout << "Invalid!\n";
break;
}
return true;
}
//********************************************
void menu(){
system("cls");
cout << "*** Menu***\n\n";
cout << " 1.Sort\n";
cout << " 2.Avrage\n";
cout << " 3.Print\n";
cout << " 4.Search\n";
cout << " 5.Exit\n";

char menu;
cin >> menu;
switch (menu){
case '1': sort();
break;
case '2':avrage();
break;
case '3':print();
break;
case '4':search();
break;
case '5':
system("cls");
cout << "\n---Do not bother---\n";
break;
default: cout << "Invalid!\n";
break;
}
}
//***********************************************
//***********************************************
int main(){
getGrades();
menu();
return 0;
}