-
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;
}
-
Re: C++ Error...IDK what is wrong!
this
should be:
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;
-
Re: C++ Error...IDK what is wrong!
it still says
1>.\demo.cpp(9) : error C2106: '=' : left operand must be l-value
-
Re: C++ Error...IDK what is wrong!
-
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;
}
-
Re: C++ Error...IDK what is wrong!
OK, so do you want to click the save button or should I?:rolleyes:
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.
-
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
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
ahoodin
OK, so do you want to click the save button or should I?:rolleyes:
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 :lol:
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
Frederick Lenz
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. :thumb:
-
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.
-
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
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
ahoodin
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
-
Re: C++ Error...IDK what is wrong!
Quote:
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!
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
ahoodin
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........
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
Frederick Lenz
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. :D, 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. :D:thumb:
-
Re: C++ Error...IDK what is wrong!
thank you guys...you have been a great help..with the code and encouragement
-
Re: C++ Error...IDK what is wrong!
I think your missing the point.
You will overcome me when you read that book, become a good student and then a good programmer.
Now, you have a long trek ahead my little padwan and when you overcome me I will be in the prolly b in the nursing home or my grave...but definitely retired. You can dance on my grave or you can square dance with me in the nursing home. I don't care, but you are wasting time when you could be learning. I wont tell you how to do this stuff, because you havent made the first effort to learn it.
You haven't even remembered to save your program, so I know you aren't thinking hard about this stuff. You just want somebody to do it all for ya. Dont ya. You think thats us. :p
Now go forth and learn!
-
Re: C++ Error...IDK what is wrong!
Come on man lay off the guy. At least he made an effort to get here.
He needs to study more, but we should motivate him not make him feel bad for asking a question. If he knew he wouldn't be here.
..... how many times have you used a var or pointer without intilizing it??? It happens to the best of us!!!
-
Re: C++ Error...IDK what is wrong!
-
Re: C++ Error...IDK what is wrong!
-
Re: C++ Error...IDK what is wrong!
i know...i was kidding about the whole 'overcoming' thing...my friend has a giant book on c++ im gonna use. i'd say by the end of this year i'll have a good bit of knowlege in my head...don't criticize me for my unexpected burst of strange optimism
-
Re: C++ Error...IDK what is wrong!
ty . i'll get right on it
-
Re: C++ Error...IDK what is wrong!
-
Re: C++ Error...IDK what is wrong!
i'm getting off now but that second link is awesome...i wanted to learn about makingwindows...ty for all the help..ill probably end up talking to one of u guys again...bye
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
Frederick Lenz
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
Actually, you can.
a = b = c = d = e = 2;
will set everything to 2.
-
Re: C++ Error...IDK what is wrong!
yes, i know you can do it like that...
i meant like this
if a = 2
a =b
b = c
c = d
d = e
then e =
-
Re: C++ Error...IDK what is wrong!
Unfortunately all those variables will be of undefined value the way you have it. The code following that would crash horribly. That is why you honestly need to make an effort read and learn.
-
Re: C++ Error...IDK what is wrong!
Actually your chain is a bit too "quick". Instead of
a = 2;
a = b;
b = c;
c = d;
d = e;
you should do
a = 2;
b = a;
c = b;
d = c;
e = d;
which of course is the same as
a=b=c=d=e=2;
Of course I won't write you to read a good book on the subject, because it has been said quite a few times :) Good luck
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
TomekL
Actually your chain is a bit too "quick". Instead of
a = 2;
a = b;
b = c;
c = d;
d = e;
you should do
a = 2;
b = a;
c = b;
d = c;
e = d;
which of course is the same as
a=b=c=d=e=2;
Of course I won't write you to read a good book on the subject, because it has been said quite a few times :) Good luck
Welcome to the board, but why bump a two month old post?
-
Re: C++ Error...IDK what is wrong!
Quote:
Originally Posted by
GCDEF
Welcome to the board, but why bump a two month old post?
Hi,
sorry, I haven't noticed the date. After registration I just clicked a thread on a main page to see what's going on. Now it appears it was "Hottest CodeGuru Threads" section and it's "hottest" in a rather big time span. My bad.