4 Replies - 644 Views - Last Post: 22 January 2013 - 06:47 AM Rate Topic: -----

#1 Orion_17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-January 13

error:lvalue required as left oparend of assignment

Posted 22 January 2013 - 05:01 AM

#include <stdio.h>
int main (void)
{
    int a[100];
    int b[100];
    int i;
    for (i=0;i<100;i++)
    {
        if(i%2=1) printf("%d",i);
    }
    return 0;
}

This post has been edited by jimblumberg: 22 January 2013 - 06:41 AM
Reason for edit:: Added missing code tags. Please learn to use them properly.

Is This A Good Question/Topic? 0
  • +

Replies To: error:lvalue required as left oparend of assignment

#2 erik venn  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 17-January 13

Re: error:lvalue required as left oparend of assignment

Posted 22 January 2013 - 05:18 AM

i don,t know much about c but it seems you are doing wrong also i dont know why u are using variable a and b ,,i dont find it useful anymore

#include <stdio.h>
int main ()
{
int a[100];
int b[100];
int i;
for (i=0;i<=100;i++)
{
if(i%2==1) printf("%d",i);
}
return 0;
} 




or if you want to use your variable use this one..

#include <stdio.h>
int main ()
{
int a[100];
int i;
for (i=0;i<=a;i++)
{
if(i%2==1) printf("%d",i);
}
return 0;
} 




Quote

for (i=0;i<=100;i++)


it will be
(i=0;i<100;i++)

Was This Post Helpful? 0
  • +
  • -

#3 erik venn  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 17-January 13

Re: error:lvalue required as left oparend of assignment

Posted 22 January 2013 - 05:26 AM

[quote name='erik venn' date='22 January 2013 - 05:18 AM' timestamp='1358857102' post='1788071']
i don,t know much about c but it seems you are doing wrong also i dont know why u are using variable a and b ,,i dont find it useful anymore

#include <stdio.h>
int main ()
{
int a[100];
int b[100];
int i;
for (i=0;i<100;i++)
{
if(i%2==1) printf("%d",i);
}
return 0;
} 




or if you want to use your variable use this one..

#include <stdio.h>
int main ()
{
int a[100];  ,,,, also you have to define value for a
int i;
for (i=0;i<=a;i++)
{
if(i%2==1) printf("%d",i);
}
return 0;
} 



Was This Post Helpful? 0
  • +
  • -

#4 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: error:lvalue required as left oparend of assignment

Posted 22 January 2013 - 05:52 AM

View PostOrion_17, on 22 January 2013 - 10:01 PM, said:

#include <stdio.h>
int main (void)
{
int a[100];
int b[100];
int i;
for (i=0;i<100;i++)
{
if(i%2==1) printf("%d",i);
}
return 0;
}


Sorry but i don't understand what the point of the arrays a & b are. They are never used nor needed as you never assign any data.
int main(void) {
  for(int i=0; i < 100; i++) {
    if(i%2=1)
      printf("%d",i);
  }
}

This post has been edited by DaneAU: 22 January 2013 - 07:41 AM

Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is offline

  • member icon


Reputation: 4141
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: error:lvalue required as left oparend of assignment

Posted 22 January 2013 - 06:47 AM

Also remember that "=" is the assignment operator "==" is the comparison operation. Noting that fact look closely at your if statement.

In the future please ask questions in the body of your post,not the title or in the code which you placed within code tags.

:code:

If you have compiler error messages, post the complete error messages. These messages have importatant information embedded within them.

Jim
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1