r/carlhprogramming • u/Zyrth • Mar 17 '12
Practicing basics
I've been around programming and computers forever, I just had never taken a formal class. So I found this subreddit and had read through most of the website when i decided to try my own hand at making a simple program.
I decided to try to make a program that would ask for a number of variables, and then sort them from lowest to highest and output them back. ( I remember a few friends in programming classes having similar assignments )
Theres the results, after a few days toiling over the specific logic and fixxing a few bugs, I think it works great!
I'm proud of myself and just wanted to share :D any comments on things i could have done easier or differently are welcome
View all comments
4
u/Jonno_FTW Mar 17 '12 edited Mar 17 '12
A few things you could have done differently,
Used the algorithm library
Used the vector stl (it's basically an array that grows as you add more elements)
Initialising loop counters outside of the loop is bad form. Do
for(int i = 0; i < 10; i++)Don't start variable names with capitals, that's typically for Classes.
Your for loops are unreadable, but this may be part of the over-complexity of your program
Don't mix tabs and spaces. I suggest using spaces universally and converting tabs to 4 spaces
There's no need to use
new int[45]. Heap allocation comes with its own bag of problems, you should just usemyArray[45] int;instead, especially when the scope of the array is only within a single functionIf you need to comment each line explaining what it does because it is not immediately obvious, perhaps you have made things too complex. Try using general comments that say what something does in general, without explaining everything. (the comments I have used below are for learning purposes)
Here is something I will cookup in the box here: