Kilsen123
Kilsen123

Reputation: 1

C++ invalid operands and types

Getting these errors in my equations for A and B, and then the other errors are from is at the end of calcit when im trying to pass it to slopeit

  [Error] invalid operands of types 'int [3]' and 'int [3]' to binary 'operator*'
 [Error] invalid operands of types 'double' and 'int [3]' to binary 'operator*'
[Error] invalid conversion from 'int' to 'double*' [-fpermissive]
 [Error] cannot convert 'int*' to 'double*' for argument '2' to 'void slopeit      (double*,double*,       int, double&, double&, double&)'
     double slops[3], yints[3], boards[3];
     double yint15,yint20,yint25,slop15,slop20,slop25,rsq15,rsq20,rsq25;
     double board;

    void calcit (double tim15[], double tim20[], double tim25[], double tem15[],
        double tem20[], double tem25[], int indx, int board,int temperature)
     {
double B;
double A;
double time;
double slopsofslops;
double yofslopes;
double rsq;
double yint15,yint20,yint25,slop15,slop20,slop25,rsq15,rsq20,rsq25;
slopeit(tim15, tem15, indx, slop15, yint15, rsq15);
slopeit(tim20, tem20, indx, slop20, yint20, rsq20);
slopeit(tim25, tem25, indx, slop25, yint25, rsq25);


yints[0]=yint15;               
yints[1]=yint20;
yints[2]=yint25;

boards[0]=15;
boards[1]=20;
boards[2]=25;

slops[0]=slop15;
slops[1]=slop20;
slops[2]=slop25;


indx = 3;


time = pow(e,(temperature -B)/A);
A = (slops * boards) + yofslopes;
B = (yofslopes * boards) + yints; 

//Pass the values needed into writeit and finished 

slopeit(board, slops, indx, slopsofslops, yofslopes, rsq);
       }
  void slopeit(double x[], double y[], int n, double& m, double& b, double& r)

Upvotes: 0

Views: 1267

Answers (4)

Vinay Shukla
Vinay Shukla

Reputation: 1844

You need to pass pointers to the function as per your definition

  slopeit(board, slops, indx, *slopsofslops, *yofslopes, *rsq);
       }
  void slopeit(double x[], double y[], int n, double& m, double& b, double& r)

Upvotes: 0

Michael Bentley
Michael Bentley

Reputation: 1

[Error] invalid operands of types 'int [3]' and 'int [3]' to binary 'operator*'

This error is due to the following line:

A = (slops * boards) + yofslopes;

Both slops and boards are of type double[3]. C++ can't multiply arrays. You'll either need to use a different class that can support it, such as the QVector3D class in the Qt library, or you'll need to calculate the product (either cross product or dot product) in a for loop yourself.

[Error] invalid operands of types 'double' and 'int [3]' to binary 'operator*'

This error is due to the following line:

B = (yofslopes * boards) + yints; 

yofslopes is of type double and boards is double[3]. Similarly, C++ doesn't support doing these kinds of operations. They are incompatible types. You'll probably want to perform a for loop to multiply each element by yofslopes (is what you're after here?). You also can't add one array to another array.

It's unclear what you're trying to do here because here's the unit analysis of that line:

double = (double * 3dVector) + 3dVector

That doesn't make sense...

[Error] invalid conversion from 'int' to 'double*' [-fpermissive]

This error is from the following line:

slopeit(board, slops, indx, slopsofslops, yofslopes, rsq);

You have a global variable called board which is of type double (not double*). Then you defined a local variable (in the parameters of calcit) with the same name, but of type int (not double*). You shouldn't pass in an integer and interpret it as a pointer without explicitly casting it.

[Error] cannot convert 'int*' to 'double*' for argument '2' to 'void slopeit

Not sure what this error is indicating.

Hope this helps!

Upvotes: 0

woolstar
woolstar

Reputation: 5083

And in your call to slopeit() you call the first argument with board instead of boards. board is a double, boards is a double[].

Upvotes: 0

Some programmer dude
Some programmer dude

Reputation: 409176

C++ doesn't have any built-in operators to operate on arrays, you have to create your own overloads.

As for the last errors, an array of (or a pointer to) int is not the same as an array of (or pointer to) double. You have to create a new temporary double array, fill it in from the int array, and pass the double array to the function.

Upvotes: 1

Related Questions