Vector



What is wrong with this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
#include <vector>
#include <math.h>

vector <double> x(16);
int times;
double sqrt;
int main()
{
	for ( times=0; times < 16; times++)
	sqrt = sqrt (times)
	{
		cout <<
The same name sqrt denotes a variable and a function. So the compiler will issue an error. I think you meant

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

vector <double> x(16);

int main()
{
	for ( std::vector<double>::size_type i = 0; i < v.size(); i++ ) 
	{
		v[i] = sqrt( ( double )i );
	}
I don't think he meant anything. Looks like a "Find the error in this code snippet" homework problem to me.
Topic archived. No new replies allowed.