hey, i've been doing c++ for uni for a few months and have got an assignment which is giving me some problems... i have to use data from a txt file, import it into c++, perform calculations with it, then produce an output file which is to be made into a graph in excel.

using the txt file data, the program should accept two angles and return x and y values.

we;ve been given a separate csv file which reads the data and saves it into something excel can read.

i wouldnt be surprised if my code is a total mess, i cant make any sense of this textbook.

heres my code:

#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <iomanip.h>

int read_data(double angles1[],double angles2[]);
void save_data(double x[],double y[], int numpts);

void main()

{	double angle1,angle2;
	double m1, m2;
	const int MAXSIZE=201;
	double x[MAXSIZE], y[MAXSIZE];
	double angles1 [MAXSIZE], angles2 [MAXSIZE];
	int numpts = read_data(angle1,angle2);
	const double pi = 3.141592653589793;
	save_data (x[],y[],numpts);
	

{	
	for (int i=0; i<numpts; i++)

	double m1 = tan(pi*angles1[i])/180;
	double m2 = tan(pi*angles2[i])/180;
	x[i] = 50.25*(m2-m1)/(m2+m1);
	y[i] = 100.5 *m1*m2/(m2+m1);
	cout<< x[i] << y[i];

}
}

here is the file given... everything is correct in this one.

#include <iostream.h>
#include <fstream.h>


// The following function will read two columns of data from the file called 'triangulation.txt' into arrays angles1 and angles2


int read_data(double angles1[],double angles2[])
{
 	double  angle1,angle2;
	int i=0;
ifstream infile;
infile.open("triangulation.txt");
if (!infile) {
	cout <<"file not found"<<endl;
	return 0;
	}


while(!infile.eof())
{

    infile >> angle1 >> angle2;
	angles1[i] =angle1;
	angles2[i] =angle2;
	
	i++;
	
}
infile.close();
return i-1;
}

// The following function will write as two columns of data, the arrays x and y, to the file called 'output.csv' 


void save_data(double x[],double y[], int numpts)
{
	ofstream outfile;
    outfile.open("output.csv");
	for (int i=0;i<numpts;i++)
	{
      outfile<<x[i]<<","<<y[i]<<endl;
    }
	outfile.close();
}

Im getting these errors at the moment...

error C2664: 'read_data' : cannot convert parameter 1 from 'double' to 'double []'

error C2664: 'save_data' : cannot convert parameter 1 from 'double' to 'double []'


if someone could tell me what they mean it would be much appreciated, i tried to search previous forums with the same error but cant find whats wrong with mine.

Look closely at one of the errors:
error C2664: 'read_data' : cannot convert parameter 1 from 'double' to 'double []'

The prototype says:

int read_data(double angles1[],double angles2[]);

The first parameter requires an array of doubles

When you call the function:

int numpts = read_data(angle1,angle2);

what type of data is angle1? Is it an array of doubles? Now look at the error again...

That should get you started....

haha that makes me feel really dumb....except i now have an error telling me i havent declared numpts. i thought i'd declared it in the void save brackets?

you must have changed something. post new code where the problem is.

i actually think i didn't change the first problem properly... i can see that my original code used int numpts = ....
and now i've deleted the whole int numpts bit. i tried modifiying it using int numpts on the problem line but couldnt get any success.

#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <iomanip.h>

int read_data(double angles1[],double angles2[]);
void save_data(double x[],double y[], int numpts);

void main()

{
	double angle1,angle2;
	double m1, m2;
	const int MAXSIZE=201;
	double x[MAXSIZE], y[MAXSIZE];
	double angles1 [MAXSIZE], angles2 [MAXSIZE];
	int read_data(double angles1[],double angles2[]); [B]//edited part[/B]
	const double pi = 3.141592653589793;
	save_data (x[],y[],numpts); [B]// syntax error ']'[/B]
	

{	
	for (int i=0; i<numpts; i++)

	double m1 = tan(pi*angles1[i])/180;
	double m2 = tan(pi*angles2[i])/180;
	x[i] = 50.25*(m2-m1)/(m2+m1);
	y[i] = 100.5 *m1*m2/(m2+m1);
	cout<< x[i] << y[i];
	
}
}

error C2065: 'numpts' : undeclared identifier
error C2059: syntax error : ']'

line 19: don't include the square brackets when passing variables, like this save_data (x,y,numpts); lines 23-29: you need to add open and closuing braces { and } to make all those lines part of that loop. Without those braces only line 25 is part of the loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.