![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#41 |
|
Hobbyist Programmer
|
Hmmmmm... This operatores section is really big and hard to memorize...
I mean, things like = and == or % or ! and so on are easy for one to memorize, but bitwise operators and priority operators (for example) are getting a bit confusing... Specialy (so far) the Logical operators... I can't seem to understand how to use && and ||, could someone care to explain it to me, please?
__________________
PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA |
|
|
|
|
|
#42 |
|
Hobbyist Programmer
|
Sorry for the triple post, but...
Can someone tell me what I'm missing in this code? I've already fixed 5 errors or something like that, but those remain, and I don't get it... =/ #include <iostream>
using namespace std;
string str1;
int a;
int b;
int c;
float d;
float e;
int main();
{
int a = 2;
int b = 5;
float d = 0.5;
cout << "stupid little operators test by Broax...\n";
a + b = c;
c + d = e;
e >= 4 ? cout << "testA" << : << "testeB" << endl;
cout << "The result is: " << e << endl;
return 0;
}Once again I think this is self-explanatory... It's just supposed to output some basic text, and then the result of some basic math thingy... Anyway, I'm having problems with all this new stuff I've learned and, most importantly... I CAN'T DEFINE VARIABLES!!!!! ![]() I thought I was supposed (or that at least I could) declarate them in the beginning of the code, and then define the value whenever I felt like it (for example, a diferent value inside each function If I wish to)... What I mean is this: int number; int main() number = 2; Or..... int number = 2; int main() bla bla bla On the first example I'd define a global variable and on the second example I'd declare a local variable... Apparently I got something wrong, so I'd appreciate some help on that...
__________________
PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA |
|
|
|
|
|
#43 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
#include <iostream>
using namespace std;
***************************0************************
string str1;
int a;
int b;
int c;
float d;
float e;
int main();***************1*****************
{
int a = 2;
int b = 5;
float d = 0.5;
cout << "stupid little operators test by Broax...\n";
a + b = c;*****************2*********************
c + d = e;*****************3*********************
e >= 4 ? cout << "testA" << : << "testeB" << endl;**************4*****************
cout << "The result is: " << e << endl;
return 0;
}refer to the areas marked by asterisks and shit... 0. these variables must be declared in the function that they are used. put them inside the "int" main" part...major programming error. 1. there is no semicolon between int main() and the first brace ( { )...minor syntax error. 2. don't think of this sign here---> = as the "equals" sign. think of it as the assignment operator. every time you think about an expression like this think this: "take what is on the RIGHT side and put that value into the LEFT side. example: int x = 3 //put the value 3 into the variable x. as soon as you think of it as this "right to left" idea, things get much easier. so when you tell the compiler to add two variables and then put a value into them it has no fucking idea what you're talking about. if "x" is a jar then you tell the program to put whatever is on the right side into the jar "x". from then on, when you say "x" it will see what you put into it. remember, in C++ "=" is the assaignment operator, "==" is what actually means "equals". point is ONLY PUT ONE THING ON THE LEFT SIDE. 3. same thing...major programming error (don't worry, the best way to learn is through errors, if you always did everything right then you're either a god or a lucky fool. the compiler can be a great teacher. listen to it. 4. i beleive you want to put an "if" statement here...major programming error. try this finished code... #include <iostream>
using namespace std;
int main() ***************1*****************
{
string str1;
int a;
int b;
int c;
float d;
float e = 6.768;
float f;
int a = 2;
int b = 5;
float d = 0.5;
cout << "stupid little operators test by Broax...\n"<<endl;
c=a+b; *****************2*********************
f=d+e; *****************3*********************
if (f >= 4)
{ cout << "the condition is held TRUE so i am printing this shit"<<endl;
} **************4*****************
cout << "The result is: " << e << endl;
return 0;
}
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. Last edited by bl00dninja; Jan 24th, 2005 at 8:50 AM. |
|
|
|
|
|
#44 | |
|
Hobbyist Programmer
|
Ok... So here I seem to have a major problem that is driving me insane!
how do I declare a global variable? and how do I assign a global value to that variable?! Anyway, most errors are regarding stupid stuff that I actually *know* but that I overlooked (I tend to do that a lot)... Anyway, for the "if" part you talked about, I was basing myself on the following passage: Quote:
![]()
__________________
PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA |
|
|
|
|
|
|
#45 |
|
Hobbyist Programmer
|
Heeeelp!
Am I that dull and annoying that no one will bother to answer anymore? ![]()
__________________
PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA |
|
|
|
|
|
#46 |
|
Programming Guru
![]() |
#include <iostream>
#include <string.h>
using namespace std;
string str1;
int a;
int b;
int c;
float d;
float e;
int main()
{
int a = 2;
int b = 5;
float d = 0.5;
cout << "stupid little operators test by Broax...\n";
c = a + b;
e = c + d;
cout << ((a >= 4)?"testA":"testeB") << endl;
cout << "The result is: " << e << endl;
return 0;
}
__________________
|
|
|
|
|
|
#47 |
|
Hobbyist Programmer
|
That doesn't actually help a fucking lot you know? You might as well say that I'm dull and annoying and get it over with........
__________________
PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA PORTUGALPORTUGA |
|
|
|
|
|
#48 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Global variables are generally declared before main. Their scope lasts throughout the entire program. You can assign them a value when you declare them, or later on in the program, it doesn't really matter.
Couple of things on the side: 1.) You would probably get more replies if you created individual threads in the appropriate forum with your questions. Honestly, I don't check introduction threads once I've said hi more than once or twice. I could almost assure you that the help you recieve will be 10 times better in the C/C++ forum in various threads than you're going to get hear. If you'd like, I can split this thread for you so the C/C++ oriented questions are in the proper forum and make a thread or two (as needed) for your various questions. 2.) From what I've learned, global variables are conventionally to be avoided.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower Last edited by Mjordan2nd; Jan 25th, 2005 at 9:55 PM. |
|
|
|
|
|
#49 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
jesus, it's only been like 12 hours since i last checked. anyways, to have a global variable, you just declare and initialize it outside of any function like so:
#include <iostream>
using namespace std;
x = 1; // <--global variable, declared and such OUTSIDE of any function
int main()
{
cout<<"here is the global variable..."<<x<<endl;
return 0;
}now, because it's global anything can change it's value and can be accessed and used and shit bu anyone. i wrote a simple crappy four-function calculator in C, C++, and Java awhile back and posted the code. i used a global variable in the version that i wrote in C to maintain a running tab on what the current value was. i'll find it and post it next...
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#50 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
............................can't find it now, double0posted by accident cuz the site went down at 0200 eastern time
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. Last edited by bl00dninja; Jan 26th, 2005 at 1:16 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|