Passing an array to a function, int and string

So, for this homework i'm doing i have to pass two values to a function, one's an int and the other is a string, i'm getting these two errors and have no idea how to handle/fix it.

invalid conversion from `int' to `int*'
cannot convert `std::string' to `std::string*' for argument `2' to `int findLowest(int*, std::string*)'

below is my code, both of these errors are in the "findLowest" function

#include <iostream>
#include <string>
using namespace std;

int getNumAccidents(string);
int findLowest(int [], string[]);

int main()
{
string borough[5];
int accident[5];

borough[0] = "Brooklyn";
borough[1] = "Manhatten";
borough[2] = "Staten Island";
borough[3] = "Queens";
borough[4] = "Bronx";

int i;
for (i = 0; i < 5; i++)
accident[i] = getNumAccidents(borough[i]);

findLowest(accident [5], borough [5]);

system("PAUSE");
}


int getNumAccidents(string borough){
int accidents;
cout << "Enter amount of accidents in " << borough << endl;
cin >> accidents;
if (accidents < 0){
cout << "Number must be higher than 0, please try again." << endl;
cin >> accidents;
}

return accidents;
}

int findLowest(int accident[5], string borough[5]){
int temp, q = 0;
string nemp;

temp = accident[0];
nemp = borough [0];
for (q = 0; q < 5; q++){
if (accident[q] < temp){
temp = accident[q];
nemp = borough[q];
}
cout << "The borough with the lowest amount of accidents is:" << endl << temp << "with " << nemp << endl;
}





 
int findLowest(int [], string[]); 

Why is this returning an int? The way you are using this function, it returns nothing, so reconsider this.

Also:
 
findLowest(accident [5], borough [5]);

You probably think that this passes the arrays to the function, but it actually doesn't. What this is trying to do is pass in the 6th element of the arrays (these elements don't even exist, but the compiler won't care about that). So basically, this is trying to pass a single int and a single string into a function that is expecting an array of ints and an array of strings. Simply removing the "[5]"s altogether will remove your problem.

Also, your findLowest function needs one more ending brace on the end of it; you have the 2 there that end the for and if statements, but not one to actually end the function. However, if you just add the last ending brace on to the end, your cout statement will be inside the for loop, and you probably don't want that statement printing five times (although maybe you do, I don't know) so watch out for that.

One last thing, not a fatal error or anything:
 
int findLowest(int accident[5], string borough[5]){

You probably already know this, but you don't have to give these arrays specific sizes, they just will be the size of whatever arrays are passed in to the function. There's nothing wrong with giving them specific sizes here though.

I think that's about it. Good luck. Let me know how it works out.
Last edited on
uhh, well i changed the int to void and i deleted the [5]s, and while i'm not getting the same errors anymore now i'm getting these errors:
invalid types `int[int]' for array subscript

three of them, in the second function, anywhere where the accident array is present within the function
Well, just look at your cout line, and what the variables in it mean, and what order you put them in. The program is printing out exactly what you're telling it to, it's just not quite what you want.
Topic archived. No new replies allowed.