for loop not working but cant find the error

this is suppose to be a parallel array and each array contains five elements but i can't see where i went wrong with the for loop. i compiled the code and after the first loop, the code breaks and i immediately exit out of the loop.

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
#include <iostream>
using namespace std;

/* function prototypes */

void initializeArrays(string names[], int wins[], int size);
void sortData(string names[], int wins[], int size);
void displayData(string names[], int wins[], int size);


/* main function */

int main() {

    // initializing two arrays
    string teamNames[] = {};
    int teamWins[] = {};
    int teamSize = 5;

    initializeArrays(teamNames, teamWins, teamSize);

    return 0;
}


/* function definitions */

void initializeArrays(string names[], int wins[], int size) {

    for (int i = 0; i < size; i++)
    {
        cout << "Enter team #" << i+1 << ": ";
        cin >> names[i];
        cout << "Enter the win for team #" << i+1 << ": ";
        cin >> wins[i];
    }

}

void sortData(string names[], int wins[], int size) {

}

void displayData(string names[], int wins[], int size) {

}
closed account (48T7M4Gy)
To declare an array of 5 blank strings you should write
1
2
const int size = 5;
string teamNames[size];


i fixed that. thanks!
That's why I always recommend using some programs like checkamrx to detect errors. Of course, the best way is to program slowly and detect each bug before it happens.
Registered users can post here. Sign in or register to post.