Be careful how you present your advice. If it is opinion, don't state it as fact.
1. His indent style is called Banner style. (And a couple instances of Pico style.)
http://en.wikipedia.org/wiki/Indent_style
There are several things to remember about indent styles
- there is no such thing as "The One True Brace Style" --no matter how much K&R advocates (or <your favorite style advocates>) would like you to believe it.
- when coding,
consistency is more important than pretty-printers
- when working on a team project, use the team project's style guidelines
- everything else is opinion and fluff
2. It is a good suggestion, but not a good idea. Readable code does not depend on braces. The following are equally valid:
if (foo) if (foo) {
baz(); baz();
}
...and equally easy to modify with more or less statements. Anyone with minimal competency in C or C++ can recognize the differences.
3. Agreed. The fatal issue is that the stack always grows but never shrinks. For a small program like this it probably isn't an issue, but it
is a bad habit.
C++ forbids users from calling
main() in their programs (and it has always been a bad thing in any case) in part for this very reason. The
Root() function is just a substitute for
main(), so that same flaw is not obviated.
When doing something multiple times, a loop is almost always the better choice.
You can fix it easily enough, due to your nice, modular design:
1. Change all calls to
Root() to a simple
return. (Your functions all say they return
int, but only
GetUserChoice() and
Root() actually do. You should also change all those to
void.)
2. Change
main() to use a loop:
1 2 3 4 5
|
int main()
{
while (Root());
return 0;
}
|
3. Add a non-terminating return code to the end of
Root() (between lines 48 and 49):
1 2 3 4
|
case 4: Circle (); break;
}
return 1; // not zero, so main() won't quit
}
|
Hope this helps.