newbie on programming
ok i just got a stupid question about programming this is my first time ever seeing codes and reading about them and some things i cant under stand like on the second tut. in Learning to Program in C++ Lesson 2: If statements i dont understand what its trying to say if some 1 can put it in lamans terms if pospible ive been trying to learn this for like 4 months and cant get passed the second lesson lol
You're going to need to post a more specific question, give a code example of a particular if statement you are having trouble understanding.
In general they work like this:
Of course there is endless complexity inherent in a conditional statement, which is why you need to provide a more specific question.
//Do something else
Sorry. Not really sure what "layman's term" I would use to describe the meaning of the word "if."
Originally Posted by FRO212
well the whole < > less and gratter thing
> greater than 5 > 4 is TRUE
< less than 4 < 5 is TRUE
>= greater than or equal 4 >= 4 is TRUE
<= less than or equal 3 <= 4 is TRUE
== equal to 5 == 5 is TRUE
!= not equal to 5 != 4 is TRUE
i under stand want to type how 5 is grater the n 4 and all that but just not how it would fit in a program and how it can be used and also it stated something about user names and i was just courious about how i would go about putting a user name and pass in to a program just for a refreance to when i do start making a program and get decent with it
Code is frustrating...
...and you'll just have to get used to it. However if you've been on that for four months, you haven't been trying very hard lol. It can be VERY usefull in programs, I still use it and I'm in the early stages of creating a full-fledged game. It can error detect such as:
I had to do a tax program before once for a class, I don't remember, but i'm pretty sure no switches were allowed. Anyway, the user input all kinds of variables for their money earned, interest earned, taxes paid, tax deductables... and so the if statements made a bulk of the actual code (that wasn't reading in data) because it had to figure out what tax bracket they were in, and what exceptions they had.
if (value == BADVALUE)
//tell user that the bad value is coming up
//run system as normal
If statements for a regular cmd window program (that black window with grey courier new font) are also great for doing simple reading in of user data for answers to questions. I had to do a price handling program imitating a local ferrie's rates. Essentially how many passengers, if they had a car or a bike, what class they were riding in, (class being just first or third, it wasa LONG time ago,) and a few other questions, most being yes/no questions. So if user input == yes, or 'y' or 'Y' or '1' or whatever, you can check for that and only execute something if it "fits the bill". There are near endless uses for if. If you look into my question in "problems with GetAsyncKeystate()" you'll see that my whole problem (I thought) was dealing with an if statement, to switch between two different (and popular) RTS camera modes.
Very useful. Try not to judge the usefullness of seemingly useless functions until you've used them before. Operator overloading to me right now, seems inherantly useless to my tastes, as I could just call the function that does what it does, but for the sake of saving coding lines, and making it easier to read, it might be usefull once I understand it's complexities and have put it to use in a few practice programs. (Probably mainly saves space for the fact that no function call is needed, and you could possibly use them to take someone elses code and completely change the use for it by adding your header file to it). Alas.. i've digressed. Just learn, THEN judge. Not the shoot-and-ask-questions-later method; much less affective in coding.
if (user is holding alt)
well on that i just never figured it out and i just started reading it againand just got stuck but i think i understand it ill probly be asking more questions on c++ but ive been verry instered in it for like 5 yrs now just never took the time to read about it and now im finaly doing so and i wish some 1 would help me under stand more but ill get threw it on my owna and ask questions i dont know and try to make a few programs