I assume from the style that you haven't started on classes, etc., as the code is more or less C with C++ i/o. So I won't include things like it would be better if you used classes, C++ standard containers, etc.
On initial impressions, some of the good points are:
1. The code is well laid out and is easy enough to follow.
2. You're not using
using std;
so you're not poluting the global namespace
3. You're using enums and consts rather than literals, at least some of the time. (Though maybe you could have used the Craps names for the dice throws? 2 = snake_eyes, 7 = natural_or_seven_out ... But I'm not sure about this?)
4. You're defining variables at first point of use.
5. You're using const
6. You're using ++i rather than ++i (Edit corrected first i++ to ++i)
When it comes to improvements
1. You could do with a comment at the head of the file explaining what the program is (rather than explaining things in normal text above)
2. main() is way too long. If a function gets bigger than a screen full (in height), then it's a bad sign. You really need to split the code up into a number of functions (this is actually my main point!)
Factoring out the list management would be a particularly good thing. Same for any other utility code (i.e. code not directly part of the game flow).
3. Your using globals for no reason (on line 7). All the work is beging done by main, so the variables could be declared within its scope. Even if you factor your code into function, there should still be no need for globals.
4. You could compact the switch statement like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// roll = 1; is in all cases, inc the default, so should
// be moved out of switch
switch (sum) // first roll test
{
case 7:
case 11:
game_result = WIN;
break;
case 2:
case 3:
case 12:
game_result = LOSE;
break;
default:
game_result = CONTINUE;
point = sum;
break;
} // end of switch
|
Well, those are the key points. Obviously there are techniques you'll be learning in the near future which help you structure more clearly.
As I've already said, I think the main thing to focus on is using function to structure things (even) more clearly.
Andy
PS Was the break for case 7, starting at line 42, deliberately omitted? (It's a benign bug as the following case does eactly the same thing). And the use of
delete[]
on looks a bit suspcious; is this a pointer to an array? The only new I can see is allocating a single list node element.