Hello KenTheNoobProgrammer,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Starting at the top the header files "conio.h>", "stdio.h" and "stdlib.h" are all C header files and not standard C++ header files. I do not see anything in you code that would require these files,
The line "unsigned short SIZE = 0;" is better not hidden in your proto types. The "unsigned short" is a small problem later in the program in the for loops when you compare an "int" to an "unsigned short". This will not stop the program from running, but it will cause a warning on compile. The bigger problem is "SIZE". When I set up your program I needed to include the "Windows.h" header file for a function I use. One of the header files that "Windows.h" includes has a typedef for "SIZE" thus causing your use of "SIZE" to be a redefinition of "SIZE" which causes an error when compiled.
I had renamed the variable to get the program to work. For a variable that changes I would suggest using lower case letters for the variable name and choose a more descriptive name, something like, "maxSize" or "maxArraySize" so that by the time you get to your functions you will know what it means especially six month from now. Upper case letters are better used for a variable that is defined as "const" or in a "#define".
These lines:
1 2 3
|
//clears iostream buffer
cin.clear();
cin.ignore(10, '\n');
|
are not needed where you have put them. There is no reason to reset the "cin" flags or clear the buffer at this time. It also causes you to enter the menu choice two times. FYI the more accepted way to use "cin.ignore()" is:
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
which requires the "limits" header file. "std::" optional if using "using namespace std;" in your program.
The function "void update(int s)" has no real use. The "SIZE" that you pass to the function is passed by value. So, when "s" is changed there is no change to "SIZE" and when the function ends and returns to where it was call from the variable and value of "s" is lost. Also I have not found where "s" is used anywhere in the program.
In the function "void dispAvg(int *arrayList)" the for loop could be written better. First starting "i" at 0 instead of 1. Then
arrayList[i - 1]
would be
arrayList[i]
. Then
i <= SIZE
could be changed to
i < SIZE
Thus decreasing the chance of trying to access the array outside of its boundary.
After I made the changes the program ran fine. I could not find any problem unless I chose 4 before I added something to the array. I suggest adding some code to "dispAvg()" function to check that the array has something to work with before you run the for loop.
Hope that helps,
Andy