Mr WallStreet wrote:
What stupidity is oozing from me at this point?
|
first, lets be clear that you are not stupid. Programming is a new way to think and do things for most people, and it takes some time to absorb all the new information, process it, and start using it correctly. You tried, which is more than 75% of the people coming here bother to do, and it bodes well for your future as a coder. That said, this is going to seem like a lot, but every one needed a mention for future code habits and maybe seeing 'how to think about it' a bit:
do not over-use auto. it just makes it harder to debug/read code later on. Say double for doubles. Auto has its place, but not on simple variables. You can make everything 'auto'. Then you have to figure out which integer was really a double type bugs.
int z{32}; //prefer this way to initialize things. Also, prefer good variable names. z means nothing unless its an axis in 3d space or some other obvious contextual and common use of the letter z. Likewise, convert() means nothing in a large program, say from what to what in the name.
your function returns an integer after cooking up a double. That may be OK, but it is more likely a bug.
z and dbl are not necessary. you can make them constants with a meaningful name or you can just use in the equation and document what it stands for in a comment. Try to avoid unnecessary code like blah = something; return blah; should just be 'return something' without the extra middleman. Also avoid unnecessary variables.
- unnecessary variables often mean you will make pointless copies of data, which is slow.
- unnecessary lines of code is that much more to debug, maintain, and comprehend when you come back to it later.
-unnecessary code may confuse other coders using or reading your work.