Small programs as such should be relatively honored, since they are a lot used as a practical examples, usually for beginners. So an appropriate review follows to be a Nobel improvement attempt of this particular variation.
Name of program
The name of a program like that must be exclusively identical with its functional behavior.
It must hint the notion as clear as possible to the user, before he wastes efforts and resources to open the "mysterious source file". The name you picked up... "Sumaster" is somehow idiosyncratic and certainly not as pretty self-explaining. It could be interpreted in many sick ways. If it tries to exalt the program by calling it "Summation Master" then it applies, but it goes a bit funny if you assimilate it.
My suggestion is simply "Sumilizer" or something a bit more simplified "Auto Summation" (enthusiasts can call it "The A.S Bot" to bring some 21s software eminence affection).
Besides that, if you are in trouble figuring a name, you can visit this powerful international internet cyber searcher and type "Good names for a ..." where ... is the target object you are seeking a good name for.
Program description
...which is missing. The description must provide some additional information about the program usage. If you will be the only one using this, there is obviously no need (except that time when we forget). If someone wants to use the program, he might be unable to guess the unique functional mechanism you invented. Tell me: how many times you got in trouble understanding how one program works?
There is no need for you to dedicate a webpage or a readme.txt. The readme.txt can be in the source file. If this is intended to be open-source. Unlikely it won't be. If this program's future involves beginners, learning from the program, then it will be kind of you to add some description. If it is for your own experience then you can decide. In each circumstance, it isn't completely irrelevant.
/* Summation automatized program by Genis
* Copyright: Free For Any Purposes
* Compilation arguments: std=c99
*
* The first thing you'll have to specify is the length of the number table.
* Enter to continue..
* Then you are typing the first number you wish to add to the number table.
* Enter to continue.. then the next number.
* When the numbers reach the length of the number table, the program will output the total of all the numbers in the number table.
*/
Internationalization
Assuming that this program will be widely used by people around the world, it could be internationalized (i.e translated to a number of regional languages). The MinGW encoding defaults to UTF-8, the char
datatype is set to be capable of representing any member of the basic execution character set and UTF-8 code units. Unicode Programming allows you to use larger set of characters.
Variable type-definition
What have you accomplished invokes:
- Readability issue.
- Portability Issue.
More pointless additional words and more time required for the user to read and digest the formed data type.. I suggest you "typedef" these data type creations.
typedef unsigned short int uint_16, word;
typedef unsigned long long int uint_32, dword;
And then use these definitions instead. Use word
and dword
if the program is intended to work under Windows.
Variable naming
Readability issue #1.
- The first name of the first variable
num
is not accurate. If someone (or you in the forgetfulness future) wants to edit/analyze the code, he/she will need more time to assimilate the exact purpose of the variable. Why not the name arrSize
since it behaves like index and it is an index. Alternatives are table_length
for snake_case or TableLength
/ tableLength
for CamelCase name styling.
- The second name of the second variable
arr
will be fine if the first variable is named arrSize
. That is if we want to name the variables by their behavior, not logical purpose. Otherwise.. you can choose table
.
total
or tableTotal
is equally good.
Inconsiderate conversion
As we found out, num
is a variable type unsigned short
. On line 10
we except signed int
as an input for num
. This will wake up some compiler optimizations, possibly -Woverflow
and it might be quite an undesired behavior after all. In the name of the sense, you can use the printf
format specifier "%hu"
which will equalize the expectations.
Problematic function termination
If you copy/paste this code into "Skype". return(0)
will turn into a clock. It will look like you are returning a clock. Get rid of the brackets! Just kidding.
Overall
I have seen better implementations of a summation. I would prefer to use space in order to move to the next number from the table. And everything happens in one-line instead of being able to pass an unlimited amount of newlines during the process of scanf
.