I wanted to open a thread for newbies also working through "Jumping into C++" and working the practice problems. I haven't found any other reference to possible solutions to these problems and want to hear how others have handled them.
I wanted to open a thread for newbies also working through "Jumping into C++" and working the practice problems. I haven't found any other reference to possible solutions to these problems and want to hear how others have handled them.
The more direct approach would be to post your actual question on a new thread, and get specific help on the topic you're stuck on.
Your post basically reads as "please send me your answers".
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Salem,
No that was not my intention at all. I was wanting to open a thread where questions/ideas/discussion about those practice problems specifically. If I was saying "Please send me your answers", I would have posted a problem for which I needed answer
So why don't you start by presenting one of the problems along with your solution. Then ask specific questions about the problem and your solution.I was wanting to open a thread where questions/ideas/discussion about those practice problems specifically
Jim
It seems unlikely that there are others who are at the same point of going through the same material as you, and are members of the same forum.
You may as well show us what you're working on. Besides, you'll be shown much better solutions from others on here who are well beyond the beginner stage.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
I am a complete newbie to coding. I am using Allain's book "Jumping into C++" as an introduction to C++. I have looked for a way to contact or read posts from others who are working through this book. At this point I am not stuck on a particular problem, but was hoping to hear from those who is working with this book. If this is an inappropriate use for this board, I apologize.
I do have an very remedial question regarding FOR loops.
As I understand from what I read in the book, when a FOR loop is defined, the variable that is utilized does not have to be declared prior to that loop, so the for definition actually declares and/or initializes a variable (or can use a variable that has already been declared).
If I were to use a variable in a FOR loop that was not previously declared, is the scope of that variable limited to that loop?
Example, just to be clear:
In this example, it is possible that variable i is declared first in this for loop. If this is the case, would i only be available for the code "cout << i <<'\n\;"? (such that this variable functions only as a marker to execute a specified number of redundant tasks). I am assuming this is the case but the book did not mention a scope concern.Code:for ( int i = 0; i < 10; i++ ) { cout << i << '\n'; }
Last edited by Salem; 02-26-2013 at 02:24 AM. Reason: fixed positioning of code tags
If you declare a variable in the loop initialization section then yes that variable is only available inside the loop. But if you want to use that variable after the loop you can declare the variable prior to the loop:
JimCode:int i; for(i = 0; i < someNum; ++i) { do something } or int i = 0; for(; i < someNumber; ++i) { do something. }
Oh, it's not so much inappropriate, it's probably just a bit too optimistic. It's better to provide something to talk about to start the ball rolling, and let the discussions go wherever they go.
Others in a similar situation are more likely to find this forum and thread if there is something interesting or useful within it that relates to their situation.
In the mean time, lets discuss something specific.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Jim, Thanks for the response. This is what I assumed, but it wasn't specified, and I didn't want to proceed on an assumption.
I do have a question. I am just starting out with C++ as you may have guessed and in the first program (the "Hello world" program) i opened the sample, pressed F9 and of course it said, "Hello world."
Heres the thing thats getting me...
the program:
Code:# include <iostream>Now correct me if im wrong, but shouldn't the program show "HEY, you, I'm alive! Oh, and Hello World!" as opposed to just "Hello World!"? The book tells me I should play around with the program and try to make it say different things. No matter what I type, or omit within the quotations it always says "Hello World!" when I execute it.Code:using namespace std; int main () { cout << "HEY, you, I'm alive! Oh, and Hello World!\n"; }
Now I could be overlooking something obvious but right now I havent a clue why its doing that. Help?
EDIT: Actually at this point, it doesnt matter if i start a new project or anything, for the hell of it i clicked "Run" and it did it again. I guess im not using Code::Blocks correctly i guess....
EDIT: Managed to get it to stop the Hello World program... kind of... now when i put in the program its telling me that "<iostream>" doesnt even exist ("no such file or directory")
Last edited by Wilave; 03-05-2013 at 01:43 AM.
For the original issue, every time you make a change to the code you will need to save the change and recompile before running it in order for it to take effect.
>>EDIT: Actually at this point, it doesnt matter if i start a new project or anything, for the hell of it i clicked "Run" and it did it again. I guess im not using >>Code::Blocks correctly i guess....
I just tried simulating the problem and I'm not able to reproduce. The F9 on Code::Block actually recompiles and runs the compiled code. So for sure I would expect to see the changes you've made.
One other things I noticed was that, the code::block takes the text from the current editor buffer. Meaning you dont have to save the code before you F9. In fact it saves and then recompiles the code. Whatever it is, you do to the code I think it should work. If it dosn't I strongly suggest you close and reopen the code::block and just try it a single empty file rather than creating a new project.
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein