--Originally published at my programming blog
The assignment of last week was to ask the user for 10 values and then calculate the standard deviation with those values, then you needed to change your program so that the user could tell you how many values he wanted to enter.
It was easy to calculate the standard deviation when you ask the user for 10 values, but when I wanted the user to tell me the size of the array I had a lot of problems.
This is what I did:
- First I did my function and in the parameters I included the array and the integer size (which is the size the user will enter).
- Then I declared my values which were floats, sum=0, average, sum2=0 and SD
- Then I did a for loop where while i was less than the value of size there will be a sum of values.
- Then that sum that was calculated I divided it by the integer size to calculate the average.
- Then I did another for loop where when i was less than the size, then there will be a sum2 that will be equal to the sum of the first value entered minus the average and that to the power of 2, (so you need to include the cmath library).
- Then I equaled SD to the sum2 divided bye the size of the array, and my function will return SD.
- In my int main I declared the integer size and I asked the user for the value of size.
- Then I declared my array with the value inside the brackets “size”. So that the program knows that the size of my array is equal to the size entered by the user.
- Then I asked the user for the values and I did a for loop where while i Continue reading "Lists!"