how i change it: left operand must be l-value
Jul 5, 2015 at 1:26am UTC
a small code , problem with " l-value"
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
const NX=200;
const NY=100;
const U=0.1;
int i,j,n,dx,dy;
double ux0[NX+1][NY+1],uy0[NX+1][NY+1],ux[NX+1][NY+1],uy[NX+1][NY+1];
void init();
void evolution();
void output(int m);
int main()
{
using namespace std;
init();
for (n=0;n<10000;n++)
{
evolution();
if (n>0)
{
if (n%100==0) cout<<"The ux and uy of [NX/2][NY/2] is:" <<ux[NX/2][NY/2]<<" " <<uy[NX/2][NY/2]<<endl;
if (n%1000==0) output(n);
}
}
system("pause" );
return 0;
}
void init()
{
dx=1;
dy=1;
for (i=0;i<=NX;i++)
for (j=0;j<=NY;j++)
{
ux[i][j]=0;
uy[i][j]=0;
ux[0][j]=U;
}
}
void evolution()
{
for (i=1;i<NX;i++)
for (j=1;j<NY;j++)
{
ux0[i][j]=ux[i][j];
uy0[i][j]=uy[i][j];
ux[i+1][j]-2*ux[i][j]+ux[i-1][j]+uy[i][j+1]-2*uy[i][j]+uy[i][j-1]=0;
}
for (i=0;i<=NX;i++)
{
ux[i][0]=ux[i][NY]=0;
uy[i][0]=uy[i][NY]=0;
}
for (j=0;j<=NY;j++)
{
ux[0][j]=U;
uy[0][j]=0;
ux[NX][j]=ux[NX-1][j];
uy[NX][j]=uy[NX-1][j];
}
}
void output(int m)
{
ostringstream name;
name<<"FDM_" <<m<<".dat" ;
ofstream out(name.str().c_str());
for (i=0;i<=NX;i++)
for (j=0;j<=NY;j++)
{
out<<double (i)<<" " <<double (j)<<" " <<ux[i][j]<<" " <<uy[i][j]<<endl;
}
}
Last edited on Jul 5, 2015 at 1:27am UTC
Jul 5, 2015 at 1:54am UTC
Lines 11-13 are missing type specifiers.
Line 63: What exactly do you think this line does?
ux[i+1][j] - 2*ux[i][j] + ux[i-1][j] + uy[i][j+1] - 2*uy[i][j] + uy[i][j-1] = 0;
You have an expression on the left side of the equal sign. You then try to assign 0 to that expression. The left side of the assignment must resolve to an addressible variable (L-value). It can not be an expression.
I can't tell you that, because I don't understand what you're trying to do.
Last edited on Jul 5, 2015 at 1:57am UTC
Topic archived. No new replies allowed.