For loop problem - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20) +---- Thread: For loop problem (/showthread.php?tid=3646) |
For loop problem - GeneralOJB - 12-15-2009 Hey Why doesn't this work: PHP Code: #include <iostream.h> For 'x', I should be getting the same as 'i' (1 going down to 100) but I get 5050. Does anyone know what the problem is? P.S - I'm learning from a book, so any mistakes are Jeff Cogswell's fault. RE: For loop problem - Gaijin - 12-15-2009 Code: x += i; Simply means x = x + i That means your adding the "i" number to the "x" number. Try removing the + RE: For loop problem - GeneralOJB - 12-15-2009 This time I get '100' Instead of 1 2 3 4 ect. RE: For loop problem - Gaijin - 12-15-2009 Yes that is because you're declaring the x variable every time new. To do what you want you'll need an array. Code: char[] x; RE: For loop problem - GeneralOJB - 12-15-2009 (12-15-2009, 02:38 PM)Master of The Universe Wrote: Yes that is because you're declaring the x variable every time new. I'm getting an error on the 'char[] x;', it says it expected primary expression before char. Where exactley do I put this? And sorry im pretty new to C++. RE: For loop problem - Brainless Control - 12-15-2009 Is that book outdated? cause new compilers also accept <iostream> as an header. <iostream.h> is old school RE: For loop problem - GeneralOJB - 12-15-2009 Yeah, i'm using <iostream>, the original post was copied from the old book. But I do have a new compiler. It's just the book that's old. 2003. LOL RE: For loop problem - Brainless Control - 12-15-2009 2003...lol you might want to change the book you're reading to something up to date RE: For loop problem - Gaijin - 12-15-2009 (12-15-2009, 02:48 PM)GeneralOJB Wrote: I'm getting an error on the 'char[] x;', it says it expected primary expression before char. I'm the one who need to apologize. I was with my tought in a bit different language! Here Take a look at this code. Code: #include <iostream> RE: For loop problem - GeneralOJB - 12-17-2009 Love you <33 |