Superbowl Program Problem

Hello everyone. I am new to this forum and to coding so any pointers would be greatly appreciated. I am currently working on a code, but I keep getting a error as follows:

cannot convert 'std::string' to 'std::string*' for argument '1' to 'void openfile(std::string*, std::string*,...

The goal of the program is to read into the arrays. The program should then print out the arrays side by side in neat, labeled columns. It should print out the average number of points scored by the winning team, the number of winning teams that scored more than 40 points, the winner and loser in the super bowl where the most points were scored and the winner and the loser in the super bowl where the least points were scored.

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

using namespace std;

void openfile(string winteam[], string loseteam[], int rascores[], int raysize, int count);

int main()
{
    string winteam, loseteam;
    int rascores, raysize, count;

//Will read from the array
openfile(winteam, loseteam, rascores, raysize, count);

}

void openfile(string winteam[], string loseteam[], int rascores[], int raysize, int count)
{
    ifstream input;
    input.open ("superbowl.dat"); //opening the file.
    if (input.is_open()) //if the file is open
    {
        for(int i=0; i<raysize; i++)
        {
            
            getline(input, winteam[i]);
            getline(input, loseteam[i]);
            
            input>>rascores[i];
            input.ignore(80, '\n');
        }
        input.close(); //closing the file
    }
    else cout << "Unable to open file"; //if the file is not open output
    system("PAUSE");
}


The code is not complete yet, but this error message is keeping me from completing it. Thank you for your help!
You called the function openfile on line 15. For the first and second arguments, you pass a string. However, the way you've declared the function is that the first two arguments are each string arrays. Hence the compiler error.
Last edited on
So if I wanted to pass both arguments as a string array, I would have to include the brackets in line 15, similar to line 19 and 7? Correct?

1
2
//Will read from the array
openfile(winteam[], loseteam[], rascores, raysize, count);
No, you would have to declare them as arrays on line 11.
1
2
3
4
const int MAX_ARRAY_SIZE = 50; //or some sensible limit
string winteam[MAX_ARRAY_SIZE];
string loseteam[MAX_ARRAY_SIZE];
int rascores[MAX_ARRAY_SIZE];
Last edited on
Topic archived. No new replies allowed.