15,667,885 members
See more:
If i have been given 3 arrays, how do i pass these arrays through a function?

e.g

int CarID = { 1041, 7930, 3382, 2251, 1220, 7378, 9065, 9435 };
double CarValue = { 4252, 23001, 14500, 3000, 950, 4200, 1500, 10000 };
int DaysSincePayment= { 23, 35, 2, 14, 7, 51, 1, 45 };

They need to be passed into a function to give a car either 3% interest charge if the days since payment is under 30 or 6% interest if the days since payment is over 30.

C++
```using namespace std;
int counter = 0;

struct Car
{
int CarIdentifier;
double Value;
int DaysOverdue;
double Interest;
};

Car database[8] =
{ { 1001, 9000, 20 },
{ 7940, 11000, 35 },
{ 4382, 14000, 2 },
{ 2651, 4000, 14 },
{ 3020, 3850, 5 },
{ 7168, 7000, 360 },
{ 6245, 12000, 1 },
{ 9342, 10500, 45 } };

double CalcCharge(int a, int b)
{
double interest;
if ((a > 10000) || (b > 30))
{
interest = a * 0.06;
return interest;
}
else
{
interest = a * 0.03;
return interest;
}
}

int main()
{

int counter = 0;

while (counter != 8)
{
CalcCharge(database[counter].CarIdentifier, database[counter].DaysOverdue);
counter++;
}

cout << "Car ID" << setw(10) << "Value" << setw(15) << "Interest Paid" << endl;

for (int i = 0; i != 8; i++)
{
cout << database[i].CarIdentifier << setw(10) << database[i].Value << setw(10) << database[i].Interest << endl;
}

return 0;
}```

What I have tried:

Using a function of two conditions e.g. func(int a, int b) and using a if < 30 and also an if >30 statement and returning the value however no output is received as i do not understand how to handle arrays in this way.
Posted

## Solution 1

Quote:
CalcCharge(database[counter].CarIdentifier, database[counter].DaysOverdue);
You are throwing away the return value of the function.

Possibly you meant:
C++
`database[counter].Interest = CalcCharge(database[counter].CarIdentifier, database[counter].DaysOverdue);`