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.