Small error, please help. "Undeclared (first use this function)"

Hey guys, this is my first semester in C++ and i'm not grasping the whole thing yet. It's errors like these that have me ripping my hair our because I'm not able to find out where it went wrong. This is my first post so if i posted it in the wrong section, please advise and ill follow instructions accordingly.

This is 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
using namespace std;


int AddStudM (int Studm[], int MaxM=1000);
// prototypes above.

int main ()
{
    int loop=1;
    int choice;
    
    
    while (loop==1)
    {
          system ("CLS");                  
          cout << " ** MENU **\n\n"
               << "0. Exit \n"
               << "1. Add Student mark \n"
               << "2. List all student marks \n"
               << "3. Calculate the marks average \n"
               << "4. Calculate the standard deviation \n"
               << "5. Delete a student mark \n"
               << "6. find the number of students via mark \n"
               << "7. Display distinct marks and their occurrences \n";
          cout << "\n\nSelect from the menu above: ";     
          cin >> choice;
          switch(choice)
          {
               case 0:
                    cout << "Good bye\n\n";
                    system ("pause");
                    exit(0);
               case 1:
                    system ("CLS");
                    int AddStudM (int Studm[], int MaxM);
                    system ("pause");
                    system ("CLS");
                    main();
                    break;
    
               case 2:
                    system("CLS");
                    cout << "\t-- List all student marks --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 3:
                    system("CLS");
                    cout << "\t-- Calculate the marks average --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 4:
                    system("CLS");
                    cout << "\t-- Calculate the standard deviation --\n\n";
                    system ("pause");
                    break;
                    
               case 5:
                    system("CLS");
                    cout << "\t-- Delete a student's mark --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 6:
                    system("CLS");
                    cout << "\t-- Find the number of students via a mark --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 7:
                    system("CLS");
                    cout << "\t-- Display distinct marks and their occurrences --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
          }
          }
{    

 
//  1. Add a student mark!    
    
int AddStudM (int Studm[], int MaxM=1000);


            int Mark;
            int i;
            for (i=0; i< MaxM; i++);
            {
                cout << "enter mark for student: ";
                cin >> Mark;
                Studm[i]=Mark;
            } 
    i++;
    return 0;
    }
}


There error i received was

In function `int main()':
98 - Try.cpp `MaxM' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

102- Try.cpp `Studm' undeclared (first use this function)


Thank you in advance.
Last edited on
So remove the =1000 from line 93 ?


I still get the exact same error...
I've tried removing from prototype and keep in definition...
Remove from definition and keep in prototype
Remove both
Keep both

There's a few errors going on here, I'll address the typos.

Line 88 should be a } not a {

Remove the ; from the end of line93 and add a { to line 94 to define the start of your function and remove the extra one at line 106.

You need to explain what line 39 is meant to do as it is currently a line declaring a function.

See how you get on after looking that these points.
I got

In function 'int AddStudM(int*,int)':
94- default argument given for parameter 2 of 'int AddStudM(int*,int)'
8- after previous specification in 'int AddStudM(int*, int)'

Akh this code is breaking 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
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
using namespace std;

int MaxM=1000; //change
int Studm[1000]; //change

int AddStudM ();
// prototypes above.

int main ()
{
    int loop=1;
    int choice;
    
    while (loop==1)
    {
          system ("CLS");                  
          cout << " ** MENU **\n\n"
               << "0. Exit \n"
               << "1. Add Student mark \n"
               << "2. List all student marks \n"
               << "3. Calculate the marks average \n"
               << "4. Calculate the standard deviation \n"
               << "5. Delete a student mark \n"
               << "6. find the number of students via mark \n"
               << "7. Display distinct marks and their occurrences \n";
          cout << "\n\nSelect from the menu above: ";     
          cin >> choice;
          switch(choice)
          {
               case 0:
                    cout << "Good bye\n\n";
                    system ("pause");
                    exit(0);
               case 1:
                    system ("CLS");
                    int AddStudM (int Studm[], int MaxM);
                    system ("pause");
                    system ("CLS");
                    main();
                    break;
    
               case 2:
                    system("CLS");
                    cout << "\t-- List all student marks --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 3:
                    system("CLS");
                    cout << "\t-- Calculate the marks average --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 4:
                    system("CLS");
                    cout << "\t-- Calculate the standard deviation --\n\n";
                    system ("pause");
                    break;
                    
               case 5:
                    system("CLS");
                    cout << "\t-- Delete a student's mark --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 6:
                    system("CLS");
                    cout << "\t-- Find the number of students via a mark --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
               case 7:
                    system("CLS");
                    cout << "\t-- Display distinct marks and their occurrences --\n\n";
                    system ("pause");
                    system("CLS");
                    break;
                    
          }
          }
}   //change

 
//  1. Add a student mark!    
    
int AddStudM () //change
	{
            int Mark;
            int i;
            for (i=0; i< MaxM; i++);
            {
                cout << "enter mark for student: ";
                cin >> Mark;
                Studm[i]=Mark;
            } 
    i++;
    return 0;
    }
]


at least it compiles now, but inputting numbers seems to error
Topic archived. No new replies allowed.