Do you have a specific question?
Otherwise, here are a few remarks on your code:
- You are using pre-standard headers like `<iostream.h>` and `<math.h>`. These shouldn't be used today (as in, not since 15 years ago). You should use `<iostream>` and `<cmath>` (all C++ standard headers don't have the … Read More
> You should use <iostream> and <cmath> (all C++ standard headers don't have the .h, and all those taken from C (like math.h, stdlib.h, stdio.h, etc.) also omit the .h and are prefixed with the letter c).
It's also important to remember that some compilers (Microsoft's in particular) "helpfully" don't … Read More
> > declare your variables as close as possible to where you first use them
> That's debatable.
Well, I don't mean that you should give the death penalty to those who don't follow that guideline. It's a very minor offense to good style. In other words, it's good … Read More
> And if you want to debate the issue, take it up with Herb Sutter, Andrei Alexandrescu and Bjarne Stroustrup.
This reeks of appeal to authority; if you have an argument to make, make it. I've already read anything you're likely to be thinking of from those authors, and it … Read More
I think we largely agree on this topic. When I look at your example C code, I see a generalized effort to keep variables as locally scoped as possible, within bounds of reason. It's style is in complete agreement with the guideline, at least, the way I see it, which … Read More
> I'm not advocating for an obsessive compulsion to declare variables at the narrowest scope that is humanly possible, as you seem to imply that I do.
That's what I inferred from your example, which is what I believe to be excessive localization of declarations:
cout << "enter a" << … Read More