Oh my. I can't believe you are using GOTO in a "C++" program like this. There are time in which it's use may be nesisarry, but for a beginner like you, you can go ahead and make a mental note to never ever use GOTO, ever.
Also,
Code:
#include <stdlib.h>
#include <time.h>
Those are C header files. If you really must use C functions, then use:
In your inner loop (when you are comparing the guess) you are looping from 0 - MAX_GUESSES -- but you only want to loop through the guesses that exist (i.e. you have only filled out guesses from 0 - guess, not 0 - MAX_GUESSES
Also, remember that c++ arrays are zero-based indexes, so you want to loop 0 through (MAX_GUESSES - 1) in your outer loop, or you will run into trouble since guesses[MAX_GUESSES] is not defined. You can fix this simply by using "<" rather than "<=" in your outer loop.
just like english might not be your first language, this isn't mine. my prof lets me use them without deducting points so why not? i don't understand why stroustrup would have implemented this in the language when it is somewhat 'forbidden'.
just like english might not be your first language, this isn't mine. my prof lets me use them without deducting points so why not? i don't understand why stroustrup would have implemented this in the language when it is somewhat 'forbidden'.
Well, I question how good of a professor he is then. They are there, but that doesn't mean they should be used. If you are using them for something, you should have a real good reason for it. GOTO's inevitably lead to spaghetti code, and in addition, virtually anything that can be done with a GOTO statment can be done much neater with a loop. I can pretty much guarantee you you will never be hired as a C++ programmer (if that's your goal) if you simply ignore advice and create code littered with GOTOs. It's bad for a reason. I wouldn't even consider your code to be a real example of C++. It's really just BASIC in disguise.
EDIT: As a side note, GOTO isn't a C++ language feature, it's a C language feature. God knows why it was even kept in C, but the only reason it's there in C++ is because it maintains backwards comparability with C.
Last edited by Chris_F; December 12th, 2010 at 05:18 AM.
just like english might not be your first language, this isn't mine. my prof lets me use them without deducting points so why not?
Then your professor isn't teaching you programming. You should get your money back (if you paid for the course). I don't know of one professor (and I know many) that would encourage goto, and most of them would deduct points from any code that uses it.
Secondly, code littered with "goto" will not be looked at by most people that may want to help you. The reason is as what Chris_F stated -- your code will be spaghetti.
No one is going to waste time untying all of those goto knots. The code with "goto" all over the place has no structure, no logical paths, etc. So if you want to get any substantial help here, in other programming forums or websites, or even from other students/professors, ditch using "goto" and use structured concepts.
You should be learning structured programming, and using the proper looping constructs (for, while, do-while), not goto.
i don't understand why stroustrup would have implemented this in the language when it is somewhat 'forbidden'.
You and your professor should read E. Dijkstra's "Goto Considered Harmful".
Also, "goto" exists in most languages -- Stroustrup adopted it from 'C', and 'C' adopted it from most other mid to high-level languages at the time 'C' was being developed. It is a legacy command that has been around a long time, but should rarely, if ever be used, and if the program is a beginner app such as yours, it shouldn't be used at all.
My prof has genuinely expressed how we should stay away from goto statements, and has told us all about why they are bad for a program. He does deduct points if they are used in higher level classes.
And I doubt I will read that book as this will most likely be my only programming class throughout my schooling. If I do ever move on with this subject, I will take the time to learn proper coding.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.