I have two functions. One is supposed to fill in an array, and the other takes that new array, finds the lowest number in that array, and prints the subscript.
int getNumAccidents(int acc[], const int size); Fills array num_acc[]
int findLowest(int acc[], const int size); Takes num_acc[], finds lowest value and returns the subscript.
Ultimately the goal for this program is for the first function to pass the name of a borough, and capture the amount of accidents in that borough for 2010. I have an array initialized for this already.
Then the second function will take those values and find the borough with the lowest value and print it's subscript.
For now I will be happy understanding how to properly return values from a function to use in another function in Main().
I feel like I am confusing myself slightly here and would appreciate any help you can provide. Thank you in advance.
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int getNumAccidents(int acc[], const int size);
int findLowest(int acc[], const int size);
int main()
{
string borough_name[5] = {"Brooklyn", "Queens", "Bronx", "Manhattan", "Staten Island"}; //ultimately I have to run this array through getNumAccidents
int num_acc[5];
int lowest;
int input;
for (int i=0;i<array_size;i++) //Fills in num_acc with number of accidents in 2010.
{
getNumAccidents(num_acc, 5);
input = getNumAccidents(num_acc, 5);
}
for (int l=0;l<array_size;l++) //Finds lowest number within num_acc and prints subscript.
{
findLowest(input, 5);
lowest=findLowest(input, 5);
cout << "The lowest accident state is " << lowest;
}
system("PAUSE");
return EXIT_SUCCESS;
}
int getNumAccidents(int acc[], const int size) //Records the number of accidents occured in 2010 into num_acc[]
{
int num=0;
int i=0;
cout << "Enter the number of accidents that occured in 2010 \n";
cin >> acc[i];
if (acc[i]<0)
{
cout << "Please enter a number grater than 0 \n";
acc[i]=0;
cin >> acc[i];
i++;
if (acc[i]<0)
{
cout << "You have entered an incorrect value 2 times, please run program again \n";
}
}
else if (acc[i]>=0)
{
cout << " has had " << acc[i] << " accidents in 2010 \n";
i++;
}
num=acc[i];
return num; //Returns Number of accidents.
}
int findLowest(int arr[],const int size) //Finds lowest value in num_acc[] and returns subscript.
{
int lowest=0;
for (int i=0;i<size;i++)
{
if (arr[i]<arr[i+1])
lowest=i;
}
return lowest; //Should returns subscript of lowest value.
}