invalid operands of types ....
Nov 25, 2011 at 3:45am UTC
Hello, I'm getting the following error on line 39 with my code but I really don't see what's wrong :(.
error: invalid operands of types 'double*' and 'double' to binary 'operator*'
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
const double PI = 3.14159265;
double dRand(double nLow, double nHigh);
int main() {
srand(time(NULL));
double *r, *phi, *theta;
double rand_numb;
double *x, *y, *z;
int nEntries;
cout << "# of entries: " ;
cin >> nEntries;
r = new double [nEntries];
theta = new double [nEntries];
phi = new double [nEntries];
x = new double [nEntries];
y = new double [nEntries];
z = new double [nEntries];
for (int i = 0; i < nEntries; i++) {
rand_numb = dRand(0,1);
phi[i] = rand_numb * 2 * PI;
theta[i] = rand_numb * PI;
r[i] = rand_numb;
x[i] = r * sin(theta[i]) * cos(phi[i]);
//y[i] = r * sin(theta[i]) * sin(phi[i]);
//z[i] = r * cos(theta[i]);
cout << x[i] << "i + " << y[i] << "j + " << z[i] << "k" << endl;
}
return 0;
}
double dRand(double nLow, double nHigh) {
return (rand() / (static_cast <double >(RAND_MAX) +1.0)) * (nHigh - nLow) + nLow;
}
Nov 25, 2011 at 3:52am UTC
On line 39 you're trying to multiply r, which you declared on line 15 as a pointer to a double, by sin(theta[i]), which is a double. Perhaps you meant r[i] instead.
Nov 25, 2011 at 3:53am UTC
Of course! Thank you very much!
Topic archived. No new replies allowed.