Dec 17, 2013 at 7:18pm Dec 17, 2013 at 7:18pm UTC
I'm getting the error message: invalid operands of types 'double' and 'double' to binary 'operator>>'
Tried looking at other people with the same message but it didn't help with my program... It's probably something stupid..
I'm just trying to enter the value 'feq' into my 1D force array. The same with 'm' into the moment array. They're inside a loop as well but I don't think that's the problem?
Edit: added more code for clarity
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
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
//Function Prototypes
double Moment(double feq, double xeq);
int main()
{
int nrows(0);
double moment[nrows];
double force[nrows];
int i(0), j(0);
double x(0), y(0);
double L, xn, xn1, w, feq, xeq, m, totmom, totforce, R1, R2;
//User inputs values
feq = (xn1 - xn) * w;
xeq = xn + 1/2 * (xn1 - xn);
//Enter force value into array - Error here
feq >> force[i];
m = Moment(feq, xeq);
//Enter moment value into array - Error here
m >> moment[i];
i++;
nrows++;
}
double Moment(double feq, double xeq)
{
double m;
m = feq * xeq;
return m;
}
I'm also getting the error message: "non-lvalue in assignment" for this piece of code:
1 2 3 4 5 6
for (int i=0; i<nrows; i++)
{
moment[i] + x = totmom;
totmom = x;
}
I want it to add all of the values of the array together.
I've declared everything and it resets the counter for 'i' so using it twice won't be an issue, will it?... What's going on?!
Last edited on Dec 17, 2013 at 8:09pm Dec 17, 2013 at 8:09pm UTC
Dec 17, 2013 at 7:49pm Dec 17, 2013 at 7:49pm UTC
Bitshifts work on integer values. Not floating point values.
moment[i] + x = totmom
Programming uses math, but it is not math. Whenever you see an equal sign = , read it as "is assigned the value of". So
totmom = x;
can be read "totmom is assigned the value of x".
moment[i] + x = totmom;
reads "element i of the moment array plus x is assigned the value of totmom".
See the problem? How can a single value be assigned across two things? (It can't. Each thing holds a complete value.)
I'm not sure what your code is supposed to be doing.
Hope this helps.
Dec 17, 2013 at 8:09pm Dec 17, 2013 at 8:09pm UTC
left = right
assigns the object right
to the object left
. Object left
must have a permanent address in the current scope (must have been declared). Expressions such as x + y
or string("hello" )
do not qualify as such.
In your example, if you want to assign the value of mom moment[i] + x
to totmom
, put totmom
on the left.
Last edited on Dec 17, 2013 at 8:11pm Dec 17, 2013 at 8:11pm UTC
Dec 17, 2013 at 8:16pm Dec 17, 2013 at 8:16pm UTC
I can't believe all I had to do was switch the equation around. THANK YOU
Dec 18, 2013 at 12:08am Dec 18, 2013 at 12:08am UTC
It's not an equation. It's an assignment. There are no equations in C++.
Glad you got it working.