The problem here is that you are modifying c more than once in a single statement. The bits --c, c++, and --c can be evaluated in any order. The results you are getting are merely the result of the order your compiler happens to do them in.
Also, the increment/decrement operators aren't generally safe to use on floats, since floats can't represent all integers exactly.
The problem here is that you are modifying c more than once in a single statement. The bits --c, c++, and --c can be evaluated in any order. The results you are getting are merely the result of the order your compiler happens to do them in.
Also, the increment/decrement operators aren't generally safe to use on floats, since floats can't represent all integers exactly.
I honestly sat at work trying to figure this all out by doing it on pen and paper. I wasted like 2 hours on this problem lol. Never say no one will help you here! lol
=============================RhinoXNA - Easily start building 2D games in XNA!Projects
Haha damn, that sucks. Theres really no point to doing it yourself, theres about a million ways to do it depending on the order of operations you use. I dont think you will ever need to use an expression like this in a real program, so if you can't figure that one out no worries.
First I'd like to say hello and that this workshop is great. I stumbled onto this website looking for resources on learning C++. I went out and bought the book recommended for this workshop and downloaded VC++ 2005.
I have two questions regarding chapter 4: I'm not 100% on the difference between = and ==. My understanding is that the = is used to give variables their definition whereas the == is used for the compiler to solve an equation. Also, where can I get the answers for the chapter quiz? I might have passed it over in one of the previous chapters but I can't seem to find them.
Hi Everyone i have just registered on game dev, and im glad as i find this C++ workshop very useful. I think the extra questions and exercises are very useful and i would like to thank the people that have put them together. I would also like to thank all the tutors for spending their time and sharing their wisdom with us.
I was looking up the short circuit evaluation question and how it would be beneficial and i found this webpage that explains it I hope this may help some people and spread some more light on it.
If C did not have defined short-circuit evaluation of logical expressions then:
char* pChar = 0; // some actions which may or may not set pChar to something if ((pChar != 0) && (*pChar != '\0')) { // do something useful }
would mean that the if statement would cause (at run-time) a dereference of the address 0 if pChar is 0. This may cause a run-time error on some systems. If short-circuit evaluation was not used in C, then the above would have to be written as:
if (pChar != 0) { if (*pChar != 0) { // do something useful } }
which is neither elegant nor obvious in meaning.
Languages that do not have short-circuit evaluation (BASIC, Pascal and FORTRAN, for example) produce such unnecessary nested conditionals.
Short-circuit evaluation is also useful when ensuring array indices are withing bounds:
int aiCount[42]; int i = getIndex("A String"); if ((i >= 0) && (i < 42) && (aiCount > 0)) { ++aiCount; }
This ensures that the increment is never carried out for out of range indices.
In Pascal, for example, the equivalent of the above code would only work with a nested if becuase if i was out of range (43, perhaps) the array reference would report an out of array bounds error at run-time.
Care must be taken however when functions have side effects:
// function with side effects: static int iBoundErrors = 0; bool checkBounds(int i) { if (i < 8) { printf("warning: using lower 8 of array\n"); ++iBoundErrors; } else if (i > 248) { printf("warning: using upper 8 of array\n"); ++iBoundErrors; } return (i >= 0) && (i <= 256); } // now use it: int x = getIndex(); if ((x < 127) && checkBounds(x)) { // do something }
The programmer may intend that all bounds errors will be reported by the checkBounds() function, but this will not happen. When x is greater or equal to 127 the checkBounds() function will not be called.
At this point there are no plans to run a future workshop. There are some technical limitations here on GDNet that make running workshops such as this difficult.
Also, I've now got a 10 month old son, am re-focused on martial arts and physical activities, and my company is working on the final stages of our own software product.
Needless to say, I'm very busy right now. But once the technical limitations are resolved I'm sure other people here on the GDNet community would be interested in running such a tutorial.
I understand, though I regret that you won't do this. Perhaps someone else will do something similar, I'd certainly would follow a tutorial created in the same manner as you did.
Actually don't understand why you are not a moderator of this board, would make it less complicated no?