I've been trying for a while to do a specific problem that our teacher gave us at school if we wanted to earn a good grade but I couldn't do it. But now, I'm actually very interested in solving this.
{
int i,n,a[100],c;
cout <<"n=";
cin >>n;
for(i=1;i<=n;i++)
{
cout <<"a["<<i<<"]=";
cin>> a[i];
}
for (i=2;i<=n-1;i++)
if (a[i]/10==0)
{
c=a[i];
a[i]=a[i-1]+a[i+1];
a[i-1]+a[i+1]=c;
}
for (i=1;i<=n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
return 0;
}
ERROR AT: a[i-1]+a[i+1]=c;
lvalue required as left operand of assignment.
The questions I have to solve with this once it's done are, for example: What will be shown for n=5 and the vector a=(22,4,10,5,16)?
Hi, Richard. I actually don't want anything to happen on that line but the reason for why that error occurs. What I'm doing with that part of the code is to apply the interchange algorithm, so that, for example, when the code is finished and I'll have to press F9 in the CodeBlocks Application, there will be a chosen n, which the problem tells me that it's 5, and then I'll have to pick the 5 numbers shown in the a vector which are 22,4,10,5,16 ex: a[1]=22, a[2]=4, a[3]=10, a[4]=5, a[5]=16.. When all of that is done, the application has to change my a[1] with a[2], so a[1] will have the value of a[2] and so on.