|
|
On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.>
its the return statement that makes your loop only run once.
|
Bisutopia19152 Posts
On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.>
BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } }
|
United States24554 Posts
I'm rusty...
i = 5; return i++;
i = 5; return ++i;
In which case will it return 5, and in which will it return 6?
|
On June 29 2013 00:11 micronesia wrote:I'm rusty... i = 5; return i++;
i = 5; return ++i;
In which case will it return 5, and in which will it return 6?
5 for the first, 6 for the second.
|
On June 28 2013 23:44 BisuDagger wrote:Show nested quote +On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about.
|
|
Bisutopia19152 Posts
On June 29 2013 00:37 3FFA wrote:Show nested quote +On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code.
|
On June 29 2013 01:21 BisuDagger wrote:Show nested quote +On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment.
|
I really prefer +=. In fact I actually had a stylistic guide in a class once that would not allow you to use the ++ operator. The autochecker for assignments would throw an error until you changed it.
|
On June 29 2013 01:50 3FFA wrote:Show nested quote +On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once ![](/mirror/smilies/frown.gif) //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment. I think I learned more in this thread than I did in class... (why was there always some gsl/pl/gstl on when I'm in school?)
|
On June 29 2013 02:12 wherebugsgo wrote: I really prefer +=. In fact I actually had a stylistic guide in a class once that would not allow you to use the ++ operator. The autochecker for assignments would throw an error until you changed it. So now instead of
void func(int i) { } int i = 42; func(i++);
you always write
void func(int i) { } int i = 42; int t; func((t = i, i += 1, t));
Yes, that's an assignment too, even though there is no = sign in the function call.
Granted, the sequence
vector<int> v(10, 0); int i = 0; v[i] = i++; Can resolve to pretty much anything your compiler wants it to, but is that a reason to avoid ++?
My C++ got really rusty from all that C# lately, geez. Had to look up all of this to make sure I'm not making mistakes...
|
Bisutopia19152 Posts
You're doing it wrong if you are using the '+' symbol at all.
#include <iostream> using namespace std; int add(int x, int y) { int a, b; do { a = x & y; b = x ^ y; x = a << 1; y = b; }while(a); return b; }
int main() { cout << add(2,6); system("pause"); return 0; }
|
wait... what are you trying to do in this code? I got lost at the beginning and then the code just changed into so many different formats that I was like then and finally,
|
Bisutopia19152 Posts
On June 29 2013 03:25 3FFA wrote:wait... what are you trying to do in this code? I got lost at the beginning and then the code just changed into so many different formats that I was like ![](/mirror/smilies/usehead.gif) then ![](/mirror/smilies/frusty.gif) and finally, ![](/mirror/smilies/confused.gif) Write it out on paper. These are bitwise operators. It means you manipulate the bits.Convert 2 and 6 in the binary format from decimal and then follow it along.
|
On June 29 2013 03:29 BisuDagger wrote:Show nested quote +On June 29 2013 03:25 3FFA wrote:wait... what are you trying to do in this code? I got lost at the beginning and then the code just changed into so many different formats that I was like ![](/mirror/smilies/usehead.gif) then ![](/mirror/smilies/frusty.gif) and finally, ![](/mirror/smilies/confused.gif) Write it out on paper. These are bitwise operators. It means you manipulate the bits.Convert 2 and 6 in the binary format from decimal and then follow it along. Oh binary! I haven't worked with those for a whole year. That explains it. Thanks, I think I understand it now
|
I'm going to have to fix this.
int add(int x, int y) ??< int a, b; do <% a = x bitand y; b = x ??' y; x = a << 1; y = b; ??> while(a); return b; %>
And while we're at it, we should create a wrapper class for int, maybe called inT, and only use that instead of the built in type. Then we overload the +, += and ++ operators for great success.
|
On June 29 2013 01:50 3FFA wrote:Show nested quote +On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once ![](/mirror/smilies/frown.gif) //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment.
Incidentally, I'm also working on a tile based game at this very moment. Using LÖVE, which is nice, because Lua is a pretty cool language and I don't have to write all the boilerplate code or all the low level opengl stuff just to do 2d rendering. Just found someone's component based entity system and I'm working on building off that.
|
On June 29 2013 04:56 Bobbias wrote:Show nested quote +On June 29 2013 01:50 3FFA wrote:On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once ![](/mirror/smilies/frown.gif) //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment. Incidentally, I'm also working on a tile based game at this very moment. Using LÖVE, which is nice, because Lua is a pretty cool language and I don't have to write all the boilerplate code or all the low level opengl stuff just to do 2d rendering. Just found someone's component based entity system and I'm working on building off that. Huh. I don't believe I've heard of Lua before. I may check it out sometime in the distant future.
|
Bisutopia19152 Posts
On June 29 2013 05:37 3FFA wrote:Show nested quote +On June 29 2013 04:56 Bobbias wrote:On June 29 2013 01:50 3FFA wrote:On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH" ; //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once ![](/mirror/smilies/frown.gif) //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment. Incidentally, I'm also working on a tile based game at this very moment. Using LÖVE, which is nice, because Lua is a pretty cool language and I don't have to write all the boilerplate code or all the low level opengl stuff just to do 2d rendering. Just found someone's component based entity system and I'm working on building off that. Huh. I don't believe I've heard of Lua before. I may check it out sometime in the distant future.
Lua is the scripting language blizzard uses to create the UI in WoW. Its one of the most popular along with python. They are really useful tl know.
|
|
|
|