Please Help! Im writing a code and cant find where my error is.

hi im new to programming and im working on my homework assisgnment but i keep getting compiling errors:

prog5.c: In function ‘int main()’:
prog5.c:24:44: error: expression list treated as compound expression in initiali zer [-fpermissive]
prog5.c:25:44: error: expression list treated as compound expression in initiali zer [-fpermissive]
prog5.c:48:45: error: expression list treated as compound expression in initiali zer [-fpermissive]
prog5.c:49:3: error: expected ‘,’ or ‘;’ before ‘{’ token
prog5.c:88:1: error: expected ‘}’ at end of input
prog5.c:88:1: error: expected ‘}’ at end of input

heres my code:

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
// program 5 
// ks

#include <iostream>
#include <string>
#include <fstream>


using namespace std;

int main()
{

        const int row = 4;
        int i;
        string name[row];

        int grades1;
        int grades2;
        int grades3;
        int grades4;
        int total[4];

        int max(grades1, grades2, grades3, grades4);
        int min(grades1, grades2, grades3, grades4);

                cout<<"***************************************";
                cout<<"Krystal Simms";
                cout<<"Program 5";
                cout<<"Gradebook Program Final";

                {
                ifstream myfile;
                myfile.open("studentgrades.txt"); //opens text file
                if (!myfile)
                {
                   cout<<"Can't find file"; //debug for if there is no file
                   return 1;
                }
                for (i=0; i<4;i++)
                  {
                        myfile >> name[i] >> grades1 >> grades2 >> grades3 >> grades4 ;
//loads in the students names from text file
                        total[i] = grades1 + grades2 + grades3 + grades4;

                  }

                int max(grades1, grades2, grades3, grades4)
                {
                        int max = grades1;

                        if (grades2 > max) {
                           max = grades2;
                          }
                        if (grades3 > max){
                           max = grades3;
                          }
                        if (grades4 > max){
                           max = grades4;
                          }
        return max;
                }

                int min(grades1, grades2, grades3, grades4);
                {
                        int min = grades1;

                        if (grades2 > min) {
                           min = grades2;
                          }
                        if (grades3 > min){
                           min = grades3;
                          }
                          }
                        if (grades4 > min){
                           min = grades4;
                          }
        return min;
                }


                cout <<"Krystal: " << max << min << total[0] / 4 << endl;
                cout <<"Quintan: " << max << min << total[1] / 4 << endl;
                cout <<"Alyce: " << max << min << total[2] / 4 << endl;
                cout <<"Kam: " << max<< min<< total[3] / 4 << endl;


                }
}[code]

Last edited on
Hi,

Please use code tags.

http://www.cplusplus.com/articles/jEywvCM9/


Please post your compile errors verbatim. We can explain what they mean.

Hope this helps
thanks for that! I reposted the code with the errors and code tags.
Hi,

That's better :+)

Lines 24 & 25 are meant to be function declarations - they need to be before main() and each parameter should have a type. Function parameters are normally marked const.

The function definitions for those same two functions should appear after main() - one cannot define functions inside another, including main() which is just another function.

You are already using arrays, is there any reason why the grades are not in an array? If they were, you could use a for loop in your min / max functions.

With line 14, you have defined a const variable which is excellent, just need to make use of it throughout the code, rather than putting 4 everywhere.

Have you learnt about structs yet? These are useful to use, instead of having multiple arrays for related things, one has an array of struct

http://www.cplusplus.com/doc/tutorial/structures/


Good Luck !!

Edit:

The min / max functions could return a const value as well:

const int min(/* your parameters here */);

This business about const is called const correctness - use const wherever you can
Last edited on
Topic archived. No new replies allowed.