new to C++ need help

You are required to declare a one dimensional data structure called Marks that will store six (7) student’s grades. The grade is a whole number within the range 0 to 100 inclusive.

Write a menu structure to facilitate the following features. Each of the below features must be executed in its own function.

• Enter/Input each students mark.
• Display all the students’ marks entered in the class.
• Search for any entered mark and return the index location.
• Determine the class average.
• Determine which student gained the highest mark in the class and the location (index) of that mark.
• Determine which student gained the lowest mark in the class and the location (index) of that mark.

this is an assignment i have for school. I did it but its not particularly right can someone plz help?

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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
 #include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>

using namespace std;

/*// Functions
void showMenu();
void showWelcome();
int studentMark( );
int ArrarySearch();
int classAverage();
int highestMark();
int lowestMark();*/

int main()
{

int Marks[7];              //index of Marks
int Grade=0;               //marks
int n;                     //counter for Marks
int flag=0;
int indexSearch=0;
float avg=0;
float sum=0;
int highest=0;
int lowest=0;
int choice;



//Welcome Function
void showWelcome();
{
	cout << "*******************Welcome to The  Grade Book !!!*******************"<<endl<<endl;

	system("Pause");
	system("CLS");

}
// Menu Function
void showMenu();
 {    
    cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");
 }


// mark function

/*int studentMark (int Grade);
{*/
	

   if(choice == 1)

   {

      for (n=0; n<7; n++)           
     {
        cout << "Please enter student's mark ";
        cin >> Grade;

        Marks[n] = Grade;   //enters grades into index
   
	    system("CLS");
     }

  

    for (n=0; n<7; n++)
    {
       cout << "The sutdent's marks are... " << Marks[n] << endl;
       cout << endl;
    }
  }

  cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");

    if ( choice == 2)
   {

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//int Arrarysearch(int indexSearch);
//{

     cout << "Enter the student's grade you wish to search for... ";
     cin >> indexSearch;

     for (n=0; n<7; n++)
     {
       
         if (Marks[n] == indexSearch)
         {
                    flag=1;
                    break;
         }


      }

      if (flag)
      {
           cout << "The student's grade entered is a Index " << n << endl;
      }
           else
      {
           cout <<"Sorry I could not find your number in this array..." << endl;
      }
 
   }

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------	
	
	if ( choice == 3)
//int classAverage (int sum, float avg);
{
   
for (n=0; n<7; n++)
 {
   sum += Marks[n];
   avg = sum/7;


 }

cout << "The avearge is... " << avg << endl;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");



//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//int highestMark( int highest);

    if ( choice == 4)
{
  highest = Marks[0];
  for (n=0; n<7; n++)
  {
       if (Marks[n]>highest)
       highest = Marks[n];
  }

  for (n=0; n<7; n++)
  {
      if (highest == indexSearch)
         {
                   flag=1;
                   break;
         }
   }
}

    cout << "The highest mark is... " << highest <<  endl;
    if (flag)
    {
       cout << "The highest mark is in index " << n << endl;
    }

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 
//int lowestMark(int lowest);
 
	 if ( choice ==5)
	
{
	lowest = Marks[0];
  for (n=0; n<7; n++)
  {
       if (Marks[n]<lowest)
       lowest = Marks[n];
  }

  for (n=0; n<7; n++)
  {
      if (lowest == indexSearch)
         {
                   flag=1;
                   break;
         }
   }

      cout << "The lowest mark is... " << lowest <<  endl;
    if (flag)
    {
       cout << "The lowest mark is in index " << n << endl;
    }

}

	

	 
	 
	 if ( choice < 1 || choice > 6)

	{
		 cout <<" Invalid request Please check menu and try again"<<endl<<endl;

		 cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");
		
	if ( choice == 6)	
	{
		cout<<" Thank you for using the Grade book........ Good bye."<< endl;

		exit(0);
	
	    system("PAUSE");
     } 
	}
	
	
	      
	      return 0;
}
What do you mean by "its not particularly right"? Are we expected to read your mind to know what it is you need help with?

What exactly are you having trouble with? In what way is your program not behaving as expected?
oh sorry and no i don't expect you to read my mind i'm need to the site and it was an over site on my behalf. it does what the question asks for but i'm having trouble with the menu. and the validation to quit. The menu works just i have to select the number in an order frm 1-6. therefore if i chose option 1 then lets say i choose option 4 it doesnt work
closed account (iAk3T05o)
You're doing the function thing wrong.
It's
1
2
3
4
void menu ()
{
//blah blah
}

not
1
2
3
4
void menu ();
{
//blah blah
}
Last edited on
yea but wen i remove the ; it gives me an error and i'm not sure y either
closed account (iAk3T05o)
That's because you're making functions within the int main() function. It should be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void menu()
{
cout << Choose 1, 2 or 3 << endl;
cout << "(1) Blah" << endl;
cout << "(2) Blah 2" << endl;
cout << "(3) Blah 3" << endl;
}
int main()
{
int choose_Blah = 0;
menu ();
cin >> choose_Blah;
//rest of code
return 0;
}

not
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
 
int choose_Blah = 0;
void menu(); // adding the ; is wrong here
{
cout << Choose 1, 2 or 3 << endl;
cout << "(1) Blah" << endl;
cout << "(2) Blah 2" << endl;
cout << "(3) Blah 3" << endl;
}
cin >> choose_Blah;
//this will never work 
return 0;
}
Last edited on
closed account (zybCM4Gy)
Just a quick...question...

the question specifically states "Structure". Now I dunno the specific terms that you guys are using over there but I do know that Microsoft, Cprogramming, learncpp, all think that a structure is a struct.

So are you sure you should be using an array and not a struct?
thanks nathan2222 will try that and will post if everyting goes well. to answer fox yea we were told to use an array and a struct thanks for looking out
well the menu functions works now but i'm still the same problem when selecting the options in that i have to select it in numerical order for the code to execute. if i choose the code for that will execute and if i choose option 3 it just keeps displaying the menu until the code terminates.
closed account (iAk3T05o)
Are you writing other functions in functions?
Post the new code you have.
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237


#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
using namespace std;

int choice=0;
void showMenu( int )
{
cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: "; 
           cin >> choice;
           system("Pause");
	       system("CLS");
 

}


/*// Functions
void showWelcome();
int studentMark( );
int ArrarySearch();
int classAverage();
int highestMark();
int lowestMark();*/

int main()
{

int Marks[7];              //index of Marks
int Grade=0;               //marks
int n;                     //counter for Marks
int flag=0;
int indexSearch=0;
float avg=0;
float sum=0;
int highest=0;
int lowest=0;





	cout << "*******************Welcome to The  Grade Book !!!*******************"<<endl<<endl;

	system("Pause");
	system("CLS");

// Menu Function
 showMenu(choice);
 
   
   
	  


	

   if(choice == 1)

   {

      for (n=0; n<7; n++)           
     {
        cout << "Please enter student's mark ";
        cin >> Grade;

        Marks[n] = Grade;   //enters grades into index
   
	    system("CLS");
     }

  
        for (n=0; n<7; n++)
    {
       cout << "The sutdent's marks are... " << Marks[n] << endl;
       cout << endl;
    }
  }

   showMenu(choice);

     

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      if ( choice == 2)
   {


     cout << "Enter the student's grade you wish to search for... ";
     cin >> indexSearch;

     for (n=0; n<7; n++)
     {
       
         if (Marks[n] == indexSearch)
         {
                    flag=1;
                    break;
         }


      }

      if (flag)
      {
           cout << "The student's grade entered is a Index " << n << endl;
      }
           else
      {
           cout <<"Sorry I could not find your number in this array..." << endl;
      }
 
   }

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  showMenu(choice);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------	
	
	if ( choice == 3)

{
   
for (n=0; n<7; n++)
 {
   sum += Marks[n];
   avg = sum/7;


 }

cout << "The avearge is... " << avg << endl;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
showMenu(choice);

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



    if ( choice == 4)
{
  highest = Marks[0];
  for (n=0; n<7; n++)
  {
       if (Marks[n]>highest)
       highest = Marks[n];
  }

  for (n=0; n<7; n++)
  {
      if (highest == Marks[n])
         {
                   flag=1;
                   break;
         }
   }
}

    cout << "The highest mark is... " << highest <<  endl;
    if (flag)
    {
       cout << "The highest mark is in index " << n << endl;
    }

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	showMenu(choice);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 
 
	 if ( choice ==5)
	
{
	lowest = Marks[0];
  for (n=0; n<7; n++)
  {
       if (Marks[n]<lowest)
       lowest = Marks[n];
  }

  for (n=0; n<7; n++)
  {
      if (lowest == Marks[n])
         {
                   flag=1;
                   break;
         }
   }

      cout << "The lowest mark is... " << lowest <<  endl;
    if (flag)
    {
       cout << "The lowest mark is in index " << n << endl;
    }

}

	

	 
	 
	 if ( choice < 1 || choice > 6)

	{
		 cout <<" Invalid request Please check menu and try again"<<endl<<endl;

		 showMenu(choice);
	 }
		
	if ( choice == 6)	
	{
		cout<<" Thank you for using the Grade book........ Good bye."<< endl;

		exit(0);
	
	    system("PAUSE");
     } 
	
	
	
	      
	      return 0;
}



The structure of a program looks like this:

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
//#includes

//function declarations
void showWelcome();
int studentMark( );
int ArrarySearch();
int classAverage();
int highestMark();
int lowestMark();

int main() {


}

//function definitions

void showMenu( int )
{
cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: "; 
           cin >> choice;
           system("Pause");
	       system("CLS");
 

}

//more function definitions 


The code you have for each selection (lines 70 - 88, lines 96 - 123 etc) should go into their own functions

Your showmenu function has a return type of void, you need to have it return the users selection so that information is available for the rest of the program. You have choice as a global variable (a bad idea), it is initialised to 0, and it will always 0, so the menu would be redisplayed 6 times until you get to line 212 which gives the warning followed straight after by the menu again, then the program ends !

You also need a while loop instead of repeatedly calling the menu function. Search on this forum for TheIdeasMan bool controlled while loop

Hope all goes well.
CAN ANYONE TAKE A LOOK FOR MY QUESTION PLEASE??
FROM ADIBAHHUSNA
@adibahhusna (2)

Don't bust in on other peoples topics - it is rude.

If no one has replied to your topic then consider why that is. It has only been 2 hours since your post.

OWH,,I'M SO SORRY,I DIDN'T MEAN IT..
OKAY..THANKS A LOT FOR THE ADVICE
closed account (iAk3T05o)
You're using showmenu (choice); too many times.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
showmenu (choice);
if (choice == 1)
{
//do something
}
else if (choice == 2)
{
//do something
}
else if (choice == 3)
{
//do something
}
//others 

And follow TheIdeasMan's guidelines.
Does it work? Post your complete program including what's in the functions, that's where the problem may be.
If there's already an if statement you must use else if:
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
if(choice == 1)

   {

      for (n=0; n<7; n++)           
     {
        cout << "Please enter student's mark ";
        cin >> Grade;

        Marks[n] = Grade;   //enters grades into index
   
	    system("CLS");
     }

  

    for (n=0; n<7; n++)
    {
       cout << "The sutdent's marks are... " << Marks[n] << endl;
       cout << endl;
    }
  }

  cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");

else    if ( choice == 2)
   {

 //your code


//{

     cout << "Enter the student's grade you wish to search for... ";
     cin >> indexSearch;

     for (n=0; n<7; n++)
     {
       
         if (Marks[n] == indexSearch)
         {
                    flag=1;
                    break;
         }


      }

      if (flag)
      {
           cout << "The student's grade entered is a Index " << n << endl;
      }
           else
      {
           cout <<"Sorry I could not find your number in this array..." << endl;
      }
 
   }

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");
	
	
else    if ( choice == 3)
//int classAverage (int sum, float avg);
{
   
for (n=0; n<7; n++)
 {
   sum += Marks[n];
   avg = sum/7;


 }

cout << "The avearge is... " << avg << endl;
}

cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");





//int highestMark( int highest);

 else   if ( choice == 4)
{
  highest = Marks[0];
  for (n=0; n<7; n++)
  {
       if (Marks[n]>highest)
       highest = Marks[n];
  }

  for (n=0; n<7; n++)
  {
      if (highest == indexSearch)
         {
                   flag=1;
                   break;
         }
   }
}

    cout << "The highest mark is... " << highest <<  endl;
    if (flag)
    {
       cout << "The highest mark is in index " << n << endl;
    }


	cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");

 
//int lowestMark(int lowest);
 
	 if ( choice ==5)
	
{
	lowest = Marks[0];
  for (n=0; n<7; n++)
  {
       if (Marks[n]<lowest)
       lowest = Marks[n];
  }

  for (n=0; n<7; n++)
  {
      if (lowest == indexSearch)
         {
                   flag=1;
                   break;
         }
   }

      cout << "The lowest mark is... " << lowest <<  endl;
    if (flag)
    {
       cout << "The lowest mark is in index " << n << endl;
    }

}

	

	 
	 
	else  if ( choice < 1 || choice > 6)

	{
		 cout <<" Invalid request Please check menu and try again"<<endl<<endl;

		 cout << "Please choose a Number" << endl << endl
         << "1. To Enter and dispaly Student's Grade" << endl
         << "2. To search for a praticular grade" << endl
         << "3. To determine Average" << endl
         << "4. To view Students Higest Grade" << endl
		 << "5. To Lowest Grade"<< endl 
         << "6. To Quit" << endl << endl
		 <<"Enter selection: ";  
	   cin >> choice;

    system("Pause");
	system("CLS");
		
else	if ( choice == 6)	
	{
		cout<<" Thank you for using the Grade book........ Good bye."<< endl;

		exit(0);
	
	    system("PAUSE");
     } 
	}
	
	
	      
	      return 0;
}
Last edited on
Topic archived. No new replies allowed.