To me it looks like you already had a thread and discussion (which did give you code) here:
http://www.cplusplus.com/forum/beginner/280188/
"Double-posting" (on separate subforum, nonetheless) is usually not efficient.
Lets look at your function anyway:
1 2 3 4 5 6 7 8
|
float ContactDuration( cs, ce )
{
for (int i = 0; i < size; i++)
{
contacts[i].duration = contacts[i].contact_end - contacts[i].contact_start;
}
return contacts[i]->duration;
}
|
A function gets data via parameters. Each parameter is essentially a declaration of variable.
Does
cs
look like a variable? Is that a type? If yes, what is the name?
Does
ce
look like a variable? Is that a type? If yes, what is the name?
Where in this function the
cs and
ce are used?
What is
size
? You did not declare it inside the function, nor as parameter of function. Is it a global variable?
What is
contacts
? You did not declare it inside the function, nor as parameter of function. Is it a global variable?
You do declare variable in the
for
statement:
int i
Its lifetime is the loop. It does not exists when you do
return
.
If it would exists, its value would be equal to
size
. The loop never assigns anything to
contacts[size]
.
Why do you return one unknown value anyway, when you have computed
size values in the function?