Array errors?

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
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.
Use the assignment operator http://www.cplusplus.com/doc/tutorial/operators/
even for accessing a value in array http://www.cplusplus.com/doc/tutorial/arrays/
I understand = is not an equal sign. I want the loop to add all the values in the array together which it should do if it worked.
1
2
   moment[i] + x = totmom // basically just inputs the first value of the array
   totmom = x // reassigns x to equal the first sum 

Then as the loop reiterates, it will add all the values together until it reaches the end of the array.

My issue is with the error : non-lvalue in assignment
I don't understand what it means or what is wrong with the loop..
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
I can't believe all I had to do was switch the equation around. THANK YOU
It's not an equation. It's an assignment. There are no equations in C++.

Glad you got it working.
Topic archived. No new replies allowed.