CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Join Date
    Mar 2009
    Posts
    14

    Question C++ Error...IDK what is wrong!

    I am a beginner at C++...
    I made this but I don't knowwhat it means
    when the error says " error C2106: '=' : left operand must be l-value "
    can someone help me???

    ~this is the code~

    // assignment operator

    #include <iostream>
    using namespace std;

    int main ()
    {
    int a,b,c,d,e;
    2 = a;
    a = b;
    b = c;
    c = d;
    d = e;

    cout << "If A=2, E=D, D=C, C=B, and B=A then ";
    cout << "E=";
    cout << e;

    return 0;
    }

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: C++ Error...IDK what is wrong!

    this
    Code:
    2 = a;
    should be:
    Code:
    a=2;
    also this:
    Code:
    cout << "If A=2, E=D, D=C, C=B, and B=A then ";
    cout << "E=";
    cout << e;
    could be:
    Code:
    cout << "If A=2, E=D, D=C, C=B, and B=A then E=" << e << endl;
    ahoodin
    To keep the plot moving, that's why.

  3. #3
    Join Date
    Mar 2009
    Posts
    14

    Exclamation Re: C++ Error...IDK what is wrong!

    it still says

    1>.\demo.cpp(9) : error C2106: '=' : left operand must be l-value

  4. #4
    Join Date
    Jun 2004
    Posts
    1,352

    Re: C++ Error...IDK what is wrong!

    Post your code
    Rate this post if it helped you.

  5. #5
    Join Date
    Mar 2009
    Posts
    14

    Talking Re: C++ Error...IDK what is wrong!

    // assignment operator

    #include <iostream>
    using namespace std;

    int main ()
    {
    int a,b,c,d,e;
    a=2;
    a = b;
    b = c;
    c = d;
    d = e;

    cout << "If A=2, E=D, D=C, C=B, and B=A then E=" << e << endl;

    return 0;
    }

  6. #6
    Join Date
    Mar 2001
    Posts
    2,529

    Re: C++ Error...IDK what is wrong!

    OK, so do you want to click the save button or should I?

    rebuild all too. In other words.... save this short program, compile it, link it and run it.

    Sometimes CG is like an old Scrubs episode.
    Last edited by ahoodin; March 29th, 2009 at 11:24 PM.
    ahoodin
    To keep the plot moving, that's why.

  7. #7
    Join Date
    Mar 2009
    Posts
    14

    Unhappy Re: C++ Error...IDK what is wrong!

    the first error went away but now it says my variables are unitialized and that e = 0 when it e should =2

  8. #8
    Join Date
    Jun 2004
    Posts
    1,352

    Re: C++ Error...IDK what is wrong!

    Quote Originally Posted by ahoodin View Post
    OK, so do you want to click the save button or should I?

    rebuild all too. In other words.... save this short program, compile it, link it and run it.

    Sometimes CG is like an old Scrubs episode.
    Boy, more than half those vars aren't even initialized. ... I'm surprised the computer hasn't blown up
    Rate this post if it helped you.

  9. #9
    Join Date
    Jun 2004
    Posts
    1,352

    Re: C++ Error...IDK what is wrong!

    Quote Originally Posted by Frederick Lenz View Post
    the first error went away but now it says my variables are unitialized and that e = 0 when it e should =2
    hahaha, you posted just before I posted.

    Yep, you have to intilize the vars.

    try something like:

    b=2;
    c=3;
    d=4;
    e=5;

    .... then see what happens.
    Rate this post if it helped you.

  10. #10
    Join Date
    Mar 2001
    Posts
    2,529

    Re: C++ Error...IDK what is wrong!

    I have a cool Idea, go and get a good book!

    http://www.greenteapress.com/thinkcpp/

    And don't get mad, you have to learn how to initialize
    your variables.

    int a = 0; //Now we just declared and initialized your varable all in one step


    I'm sorry but my carpal tunnel keeps me from typing too much more.
    Last edited by ahoodin; March 29th, 2009 at 11:36 PM.
    ahoodin
    To keep the plot moving, that's why.

  11. #11
    Join Date
    Mar 2009
    Posts
    14

    Talking Re: C++ Error...IDK what is wrong!

    i understand now... you cant set a variable like 'a' to equal 'b' and 'b' to equal 'c'...i wanted to make a chain ~ where they all equaled 2...but i guess u can't

  12. #12
    Join Date
    Mar 2009
    Posts
    14

    Re: C++ Error...IDK what is wrong!

    Quote Originally Posted by ahoodin View Post
    I have a cool Idea, go and get a good book!

    http://www.greenteapress.com/thinkcpp/

    And don't get mad, you have to learn how to initialize
    your variables.

    int a = 0; //Now we just declared and initialized your varable all in one step


    I'm sorry but my carpal tunnel keeps me from typing too much more.
    thats fine...i understand

  13. #13
    Join Date
    Mar 2001
    Posts
    2,529

    Re: C++ Error...IDK what is wrong!

    i understand now... you cant set a variable like 'a' to equal 'b' and 'b' to equal 'c'...i wanted to make a chain ~ where they all equaled 2...but i guess u can't
    No, I can, but you can't cuz you haven't got that far yet. Get readin!
    ahoodin
    To keep the plot moving, that's why.

  14. #14
    Join Date
    Mar 2009
    Posts
    14

    Re: C++ Error...IDK what is wrong!

    Quote Originally Posted by ahoodin View Post
    No, I can, but you can't cuz you haven't got that far yet. Get readin!
    hahaha...ok
    i dont KNOW
    but i understand that they can't all equal themselves and stuff
    but one day i will overcome you
    and i will be all
    *boom chicka boom chicka boom*
    and you will be all
    *boop oop eep doop!*
    ......yeah.....thats exactly how it will be........

  15. #15
    Join Date
    Jun 2004
    Posts
    1,352

    Re: C++ Error...IDK what is wrong!

    Quote Originally Posted by Frederick Lenz View Post
    thats fine...i understand
    Hey don't let it get to you, we all had to start somewhere. When I first started with "C" I was so happy to print something on the screen, put the exe on a diskette, load the program on a different computer and show my friends.


    Once you get the program to print what you want then you can get rocking.


    Don't give up so fast. , I'll see if I can find a good C++ tutorial where you can copy and paste code and make it work.


    Just remember with C/C++/VC++/MFC, getting off the ground is the hardest part. People are here to help, you might have to develop a hard shell, but it's worth it.

    Keep plugging at it.
    Rate this post if it helped you.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured