Error Message

Hi Everyone! I am getting this weird error message in my code and I do not know what it means. Can someone help me out?
The error is on line 124. It reads " cannot convert `std::string' to `std::string*' for argument `3' to `void output(std::string*, int*, std::string*, int, int, int, int)'"

Thanks :)

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

string findRating(string elf[50], int toys[50]);
int getTotalNumber(string elf [50], int toys[50]);
int getNumberOver500(string elf[50], int toys[50]);
int getNameMost(string elf[50], int toys[50]);
int getNameLeast(string elf[50], int toys[50]);
void output(string elf[50], int toys[50], string rating[50], int total, int count, int high, int low);

string findRating(string elf[50], int toys[50]){
  string rating[50];
  ifstream fp;

  for (int j = 0; j < 50; j++){
    fp >> elf[j];
    fp >> toys[j];

    if (toys[j] >= 500){
      rating[j] = "*****";
    }
    else if (toys[j] > 300){
      rating[j] = "***";
    }
    else if (toys[j] > 200){
      rating[j] = "*";
    }
    else {
      rating[j] = "-";
    }
    return rating[j];
  }
}

int getTotalNumber(string elf[50], int toys[50]){
    int total;
    ifstream fp;

    for (int i = 0; i < 50; i++){
      fp >> elf[i];
      fp >> toys[i];
      total += toys[i];
      return total;
    }
 int getNumberOver500(string elf[50], int toys[50]){
  int count;
  ifstream fp;

  for (int k = 0; k < 50; k++){
    fp >> elf[k];
    fp >> toys[k];
    if (toys[50] > 500){
      count++;
    }
    return count;
  }
}

int getNameMost(string elf[50], int toys[50]){
  int high = toys[0];
  ifstream fp;

  for (int p = 0; p < 50; p++){
    fp >> elf[p];
    fp >> toys[p];
    if (toys[p] > high){
      high = toys[p];
    }
    return high;
  }
}

int getNameLeast(string elf[50], int toys[50]){
  int low = toys[0];
  ifstream fp;

  for (int m = 0; m < 50; m++){
    fp >> elf[m];
    fp >> toys[m];
    if (toys[m] < low){
      low = toys[m];
    }
    return low;
  }
}

void output(string elf[50], int toys[50], string rating[50], int total, int count, int high, int low){
  for (int h = 0; h < 50; h++){
    cout << elf[50];
    cout << toys[50];
    cout << rating[50] << endl;
    cout<< total;
    cout << count;
    cout << high;
    cout << low;
  }
}

 int main(){
  ifstream fp;
  string elf[50];
int toys[50];
  string rating;
  int high;
  int low;
  int total;
  int count;
  fp.open("elves.dat");
  if (!fp){
    cout << "Error" << endl;
  }
  for (int o = 0; o < 50; o++){
    fp >> elf[o];
    fp >> toys[o];
  }
  rating = findRating(elf, toys);
  total = getTotalNumber(elf, toys);
  count = getNumberOver500(elf, toys);
  high = getNameMost(elf, toys);
  low = getNameLeast(elf, toys);
  output(elf, toys, rating, count, high, low);
}

rating is a string. Your function expects an array of strings:
change string rating[50]
to
string rating

on line 90 and remove the square brackets on line 94 too.

edit:
OR make rating an array on line 106 and pass the array in. it depends what you want to do.
Last edited on
Topic archived. No new replies allowed.