What's wrong with my function?

Can someone tell me what I'm doing wrong with this program. I can't see why it doesn't like this line:
"cout << seconds << "\t \t" << fallingDistance(seconds, distance);"

I've googled the error message but haven't been able to understand the answers that others have gotten. The error is: "error C2664: cannot convert parameter 2 from 'iterator_traits<_Iter>::difference_type (__cdecl *)(_InIt,_InIt)' to 'double' 1> Context does not allow for disambiguation of overloaded function"

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
// This program that computes how many meters an object falls in 1 to 10 seconds.

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

double fallingDistance (int, double);                  // function prototype 
const double times = 10;                               // sets the number of loops

int _tmain(int argc, _TCHAR* argv[])
{
       // call the function using a for loop according to instructors requirement
	for (int seconds = 1; seconds <= times; seconds++) 
	{
	  cout << "Seconds          Distance \n";       //header column labels
	  cout << "_________________________ \n";       //header lines
	  cout << seconds << "\t \t" << fallingDistance(seconds, distance);  
	}

 return 0;
}
                                                       // the function
double fallingDistance (int seconds, double distance)  
{                                                      
 double g = 9.8;                  
 double d = (0.5 * g * seconds * seconds);             
 return d;                                             
}
You are missing a variable called distance - you need this to pass to the fallingDistance function.

However, because you haven't done this, the compiler has searched and found something(a function) called distance in the std namespace (because you bought in the whole standard namespace at line 7 - using namespace std;).
This distance from the std namespace is to do with iteraters -
and is a template function (which accounts for the strange template related error) and is totally what we don't want.

So to Summarise:
You need to make a variable double distance;
It may be the lazy way out but I've been wracking my brain too long on this so I just changed the variable name to something else. The program works now. Thank you so much!
Topic archived. No new replies allowed.