Logical problems

I do not know what is wrong in this code

could you check it for me ?

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 15
  

int menuM(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);
int menu2(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);
int menu3(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);
void min_max (double a[SIZE], double *min,  double *max,double *avg);
void sorter (char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);
int search(int a[SIZE],int b);
int scanner(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);
void store(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);
void display(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);
void optional(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE],int choice); 
void del(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]);

/*Main Function+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

 

int main(void) {
    
    char name[SIZE][26];
    double quiz[SIZE],final[SIZE],major[SIZE],total[SIZE];
    int id[SIZE],ch,a;
    
    scanner(name,final,quiz,major,total,id);
    menuM(name,final,quiz,major,total,id);
    
 

  
    return (EXIT_SUCCESS);
}

 

 

 

/*Function Defintion++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

 

int menuM(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
    scanner(n,f,q,m,t,id);
    int var;
    system ("cls");
    printf("\nMAIN MENU");
    printf("\n1. Display the complete students’ records.");
    printf("\n2. Student menu");
    printf("\n3. Activity Menu (Major/ Final/ Quiz)");
    printf("\n4. Add a new student  record");
    printf("\n5. Delete a student  record.");
    printf("\n6. Exit");   
    printf("\nPleses enter your choice: ");
    scanf("%d",&var);
   
    switch(var){
        case 1: display(n,f,q,m,t,id);
                system("pause");
                menuM(n,f,q,m,t,id);
        break;

        case 2: menu2(n,f,q,m,t,id);
        break;

        case 3: menu3(n,f,q,m,t,id);
        break;

        case 4: store(n,f,q,m,t,id);
                menuM(n,f,q,m,t,id);
        break;

        case 5: del(n,f,q,m,t,id);
                menuM(n,f,q,m,t,id);
        break;

        case 6: printf("\nThe program will be terminated!!");
                return 6;
        break;

        default: printf("\nThere is no such choice");
                 menuM(n,f,q,m,t,id);
                 
}}



int menu2(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
    int ids,pos,var;
    system ("cls");
    printf("\nPlease enter the student id >");
    scanf("%d",ids);
    pos=search(id,ids);
    if(pos=-1){
             printf("\n1.Return to the main menu.");
             printf("\n2.Return to the students menu.");
             printf("\nPleses enter your choice: ");
             scanf("%d",&var);
             switch(var)
             {
                       case 1: menuM(n,f,q,m,t,id);
                       break;
                       case 2: menu2(n,f,q,m,t,id);
                       break;
                       default: printf("\nThere is no such choice");
                                menu2(n,f,q,m,t,id);
                       break;}}
    else   printf("\nRank:%d \nID:%d \nName:%s \nMajor:%.2lf \nQuiz:%.2lf \nFinal:%.2lf \nTotal:%.2lf \n\n",pos+1,id[pos],n[pos][26],m[pos],q[pos],f[pos],t[pos]);          
                       
    printf("STUDENT MENU");
    printf("\n1. Update Student Major Marks.");
    printf("\n2. Update Student Final Marks.");
    printf("\n3. Update Student Quiz Marks.");
    printf("\n4. Return to main menu.");
    printf("\nPleses enter your choice:");
    scanf("%d",&var);
    
   
switch(var){
        case 1: printf("\nPlease enter the new major grade >");
                scanf("%lf",m[pos]);
                menuM(n,f,q,m,t,id);     
        break;

        case 2: printf("\nPlease enter the new final grade >");
                scanf("%lf",f[pos]);
                menuM(n,f,q,m,t,id);
        break;

        case 3: printf("\nPlease enter the new qiuz grade >");
                scanf("%lf",q[pos]);
                menuM(n,f,q,m,t,id);       
        break;

        case 4: menuM(n,f,q,m,t,id);
        break;

        default: menu2(n,f,q,m,t,id);
        break;
}}



int menu3(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
    int var,i,choice;
    double min,max,avg;
    system("cls");
    printf("\nACTIVITY MENU");
    printf("\n1. Major.");
    printf("\n2. Final.");
    printf("\n3. Quiz.");
    printf("\n4. Return to main menu.");
    printf("\nPleses enter your choice: ");
    scanf("%d",&var);
   
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
switch(var){
        case 1: min_max(m,&min,&max,&avg);
                for(i=0;i<15;i++)  printf("\n%.2lf",m[i]);
                printf("\nThe average of the major marks for all students is %.2lf\n\n",avg);
                printf("\n******database is updated******\n");
                printf("\n1.To update the major grade.");
                printf("\n2.To return to the `actibity menu`.");
                scanf("%d",&choice);
                optional(n,f,q,m,t,id,choice);
                     
        break;

        case 2: min_max(f,&min,&max,&avg);
                for(i=0;i<15;i++)  printf("\n%.2lf",f[i]);
                printf("\nThe average of the final marks for all students is %.2lf",avg);
                printf("\n******database is updated update******\n");
                printf("\n1.To update the final grade.");
                printf("\n2.To return to the `actibity menu`.");
                 scanf("%d",&choice);
                optional(n,f,q,m,t,id,choice);
        break;

        case 3: min_max(q,&min,&max,&avg);
                for(i=0;i<15;i++)    printf("\n%.2lf",q[i]);
                printf("\nThe average of the quizes marks for all students is %.2lf",avg);
                printf("\n******database is updated update******\n");
                printf("\n1.To update the quiz grade.");
                printf("\n2.To return to the `actibity menu`.");
                 scanf("%d",&choice);
                optional(n,f,q,m,t,id,choice);
        break;

        case 4: menuM(n,f,q,m,t,id);
        break;

        default: printf("\nThere is no such choice");            
        break;
}
menu3(n,f,q,m,t,id);}




void min_max (double a[SIZE], double *min,  double *max,double *avg){
     int i;
     double sum=0;
     *min=a[0];
     *max=a[0];
     for(i=0;i<15;i++){
              if (a[i+1]>=a[i]) *max=a[i+1];
              if (a[i+1]<=a[i]) *min=a[i+1];
              sum=sum+a[i];
              }
     *avg=sum/SIZE;
}



void sorter (char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
     double temp1,temp2,temp3,temp4;
     char temp[81];
     int i,pass=1,temp0;
      
        for(i=0;i<15;i++) {
              if (t[i+1]>t[i]) {
                    
                    temp[26]=n[i][26];
                    temp0=id[i];
                    temp1=f[i];
                    temp2=q[i];
                    temp3=m[i];
                    temp4=t[i];
                    n[i][26]=n[i+1][26];
                    id[i]=id[i+1];
                    f[i]=f[i+1];
                    q[i]=q[i+1];
                    m[i]=m[i+1];
                    t[i]=t[i+1];
                    n[i+1][26]=temp[26];
                    id[i+1]=temp0;
                    f[i+1]=temp1;
                    q[i+1]=temp2;
                    m[i+1]=temp3;
                    t[i+1]=temp4;
                    
                    
              }}}
       
       
       

int search(int a[SIZE],int b){
    int i,j=-1;
    for (i=0;i<15;i++){
        if(b==a[i]) return i;
        else j;
}}



int scanner(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
     FILE *data;
     int stat,count=0,;
     
     data=fopen("record.txt","r");  
     stat=fscanf(data,"%s %d %lf %lf %lf %lf",n[count],&id[count],&m[count],&q[count],&f[count],&t[count]);
     while(stat!=EOF){
           count++;
           stat=fscanf(data,"%s %d %lf %lf %lf %lf",n[count],&id[count],&m[count],&q[count],&f[count],&t[count]);
           }
     fclose(data);
     return count;
}
                      


void store(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
          int count,i;
          FILE *data;
          data=fopen("record.txt","w");
          count=scanner(n,f,q,m,t,id);
          
          if (count<=15){
               printf("\nPlease enter the name of the student:  ");
               scanf("%s",n[count]);
               printf("\nPlease enter the id of the student:  ");
               scanf("%d",&id[count]);
               do{
               printf("\nPlease enter quiz grade of the student(min 0 - max 20):  ");
               scanf("%lf",&q[count]);} while (q[count]<0 || q[count] >20);
               do{
               printf("\nPlease enter major grade of the student(min 0 - max 40):  ");
               scanf("%lf",&m[count]);} while (m[count]<0 || m[count] >40);
               do{
               printf("\nPlease enter final grade of the student(min 0 - max 40):  ");
               scanf("%lf",&f[count]);} while (f[count]<0 || f[count] >40);
               t[count]=q[count]+m[count]+f[count];
               
              
               
               for(i=0;i<15;i++)  
               fprintf(data,"%s %d %.2f %.2f %.2f %.2f\n",n[i],id[i],m[i],q[i],f[i],t[i]);
               }
               
          else printf("\nDatabase had reached its limit!!");
          fclose(data);
}
            
     

void display(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
     int i;  
     printf("Rank\tID\tName\tMajor\tQuiz\tFinal\tTotal\n");
     sorter(n,f,q,m,t,id);
     for(i=0;i<15;i++);
     {
           printf("%d\t%d\t%s\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n",i+1,id[i],n[i],m[i],q[i],f[i],t[i]);
                       }
                       }                   
     


void optional(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE],int choice){
           int ids,pos;
           if(choice==1)
                {
                             printf("\nPlease enter the student id >");
                             scanf("%d",ids);
                             pos=search(id,ids);
                             if(pos==-1)
                             {
                             while(pos==-1)
                             {
                                        printf("\nThe id is not avaliable in the list please enter the student id >");
                                        scanf("%d",ids);
                                        pos=search(id,ids);
                                        }}
                            
                                 printf("\nplease enter the new major grade");
                                 scanf("%lf",m[pos]);
                                 }
                else if(choice==2)
                              menuM(n,f,q,m,t,id);
                else 
                {
                     printf("\nThere is no such choice");
                     printf("\nPlease enter another choice:  ");
                     scanf("%d",&choice);
                     optional(n,f,q,m,t,id,choice);
                     
                     }}
                


void del(char n[SIZE][26],double f[SIZE],double q[SIZE],double m[SIZE],double t[SIZE],int id[SIZE]){
     int i,ids,j;
     j=0;
     printf("\nPlease enter the student ID no. :");
     scanf("%d",&ids);
     i=search(id,ids);
     if(i==-1){printf("\nNot Found!!");
                del(n,f,q,m,t,id);}
     else {
          n[i][26]='\0';
          id[i]=0;
          f[i]=0;
          q[i]=0;
          m[i]=0;
          t[i]=0;}
}
Do you really expect us to sift through 2 pages of code without any hint of what the problem is?

How is the above code broken? What should it be doing and what is it actually doing?
Topic archived. No new replies allowed.