Help with Updated Program

Hello,

So below is a code I have written; however, it has some specifications that are not being met and I am unsure what I am supposed to change.
1. Both the size of the array (a constant) and the array itself must be declared locally inside of int main().

2. Each option in the menu must simply call a function. Each function must at minimum pass in the array and the size of the array. You must list all function prototypes above int main () and all function definitions must appear after int main().

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
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
#include<iostream>
#include<fstream>
#include<string>

using namespace std;
long int scores [10];//defining the score array


void readingscores();
void printscores(long int * scores);
void greatest(long int * scores);
void smallest( long int * scores);
void average (long int * scores);
void entry (long int * scores);
void readFile();

void menu () {
    int choice;
    cout <<" ---------------------------------------------------\n";
    cout <<"1-D ARRAY PROCESSING MENU OPTIONS\n";
    cout<<"---------------------------------------------------\n";
    cout<< "1. Read in 10 scores from user.\n";
    cout<<"2. Read in 10 scores from the file, scores.txt.\n";
    cout<<"3. Print all scores.\n";
    cout<<"4. Print the highest score.\n";
    cout<<"5. Print the lowest score.\n";
    cout<<"6. Print the average score.\n";
    cout<<"7. Print one score (give its entry number)\n";
    cout<<"8. Quit program\n";
    
    cout<<" Enter your choice:\n";
    cin >> choice;
    
    switch (choice) {
        case 1: readingscores(); break;
        case 2:readFile(); break;
        case 3: printscores(scores); break;
        case 4: greatest(scores); break;
        case 5: smallest(scores); break;
        case 6: average(scores); break;
        case 7: entry(scores); break;
        case 8:; break;
    }
    
}
int main ()
{
  
    menu();
   
    return 0;
}
void readingscores() {
    
    for (int i =0; i<= 9; i++) //filling up the array
    {
        std::cin >> scores [i];
        
    }
    menu();
}
void printscores( long int * scores) {
    for(int i=0; i<= 9; i++)
    {
        cout << scores [i];
    }menu();
    
}
void greatest(long int * scores){
  long  int great = scores[0];
    for (int i=0; i<= 9; i++)
    {
        if (scores[i+1]>= scores[i]) {
            great = scores[i+1];
        }
        
    }
        cout <<"The highest scores is:"<< great;
    menu();
}
void smallest(long int * scores){
    long int small = scores[0];
    for (int i=0; i<=9; i++)
    {
        if (scores[i]< small) {
            small = scores[i];
            
        }
        
    }
    cout <<"The lowest scores is:"<< small;
    menu();
}
void average(long int * scores){
    long int sum = 0;
    for (int i=0; i<=9; i++) {
        sum += scores [i];
    
    }
    cout << "The average score is:"<< sum/10;
    menu();
}

void entry(long int * scores){
  long  int number;
    cout <<" Enter your number (0-9)";
    cin >> number;
    cout << scores [number];
    menu();
}

void readFile() {
    ifstream myfile ("scores.txt");
    string line;
   
    if(myfile.is_open() )
    { int i=0;
        while(getline(myfile,line) && i<=9)
        {
            cout<<line<<"\n";
            
            scores [i]= stol(line);
            i++;
        }
        
        
       
        myfile.close();
            
    
    }
    menu();
}

 /*
  ---------------------------------------------------
  1-D ARRAY PROCESSING MENU OPTIONS
  ---------------------------------------------------
  1. Read in 10 scores from user.
  2. Read in 10 scores from the file, scores.txt.
  3. Print all scores.
  4. Print the highest score.
  5. Print the lowest score.
  6. Print the average score.
  7. Print one score (give its entry number)
  8. Quit program
  Enter your choice:
  1
  2
  4
  5
  6
  7
  8
  9
  43
  34
  23
  ---------------------------------------------------
  1-D ARRAY PROCESSING MENU OPTIONS
  ---------------------------------------------------
  1. Read in 10 scores from user.
  2. Read in 10 scores from the file, scores.txt.
  3. Print all scores.
  4. Print the highest score.
  5. Print the lowest score.
  6. Print the average score.
  7. Print one score (give its entry number)
  8. Quit program
  Enter your choice:
  4
  The highest scores is:43 ---------------------------------------------------
  1-D ARRAY PROCESSING MENU OPTIONS
  ---------------------------------------------------
  1. Read in 10 scores from user.
  2. Read in 10 scores from the file, scores.txt.
  3. Print all scores.
  4. Print the highest score.
  5. Print the lowest score.
  6. Print the average score.
  7. Print one score (give its entry number)
  8. Quit program
  Enter your choice:
  
  The average score is:14 ---------------------------------------------------
  1-D ARRAY PROCESSING MENU OPTIONS
  ---------------------------------------------------
  1. Read in 10 scores from user.
  2. Read in 10 scores from the file, scores.txt.
  3. Print all scores.
  4. Print the highest score.
  5. Print the lowest score.
  6. Print the average score.
  7. Print one score (give its entry number)
  8. Quit program
  Enter your choice:
*/

Last edited on
You are supposed to declare your array inside main and pass it together with its size to the functions.
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
void readingscores(int scores[], int SIZE);
void printscores(int scores[], int SIZE);
void greatest(int scores[], int SIZE);
void smallest(int scores[], int SIZE);
void average (int scores[], int SIZE);
void entry (int scores[], int SIZE);
void readFile(int scores[], int SIZE);
void menu(int scores[], int SIZE);

int main ()
{
  const int SIZE = 10; 
  int scores[SIZE] = {0};

  menu(scores, SIZE);  
  
  return 0;
}
void menu (int scores[], int SIZE) {
    int choice;
    cout <<" ---------------------------------------------------\n";
    cout <<"1-D ARRAY PROCESSING MENU OPTIONS\n";
    cout<<"---------------------------------------------------\n";
    cout<< "1. Read in 10 scores from user.\n";
    cout<<"2. Read in 10 scores from the file, scores.txt.\n";
    cout<<"3. Print all scores.\n";
    cout<<"4. Print the highest score.\n";
    cout<<"5. Print the lowest score.\n";
    cout<<"6. Print the average score.\n";
    cout<<"7. Print one score (give its entry number)\n";
    cout<<"8. Quit program\n";
    
    cout<<" Enter your choice:\n";
    cin >> choice;
    
    switch (choice) {
        case 1: readingscores(scores, SIZE); 
        break;
    // and so on
    }
    
}
So basically what I am missing is:

 
void readingscores(int scores[], int SIZE);


and then from there I would alter that for the rest of the file and be okay?
Topic archived. No new replies allowed.