The funny thing was I changed the movingAvg[n] to movingAvg[index] in the function call, but failed to change it in the movingAvg[index]=sum/days. I have to remember that if you change one, you have to change the other.
I have another question. For the moving averages for Stock1, the average prices 2 through 6 is $35.50. For the moving averages for stock2, the average prices 11-15 is also $35.50, the only prices that are equal. However, the output,"The moving average of stock1 equals the moving average of stock2: 0 days" isn't correct. The code looks correct to me.
I have one more question. Hopefully the final one
Is there a way to "dress" up this output:
Report 3 Apr 12 2004
16 Five-day moving averages of Stock1 and Stock2
Stock 1
The average for prices 1 through 5 is: $36.30
The average for prices 2 through 6 is: $35.50
The average for prices 3 through 7 is: $34.50
The average for prices 4 through 8 is: $34.40
The average for prices 5 through 9 is: $33.25
The average for prices 6 through 10 is: $34.60
The average for prices 7 through 11 is: $35.35
The average for prices 8 through 12 is: $35.25
The average for prices 9 through 13 is: $35.30
The average for prices 10 through 14 is: $35.30
The average for prices 11 through 15 is: $36.00
The average for prices 12 through 16 is: $37.50
The average for prices 13 through 17 is: $38.80
The average for prices 14 through 18 is: $39.55
The average for prices 15 through 19 is: $40.00
The average for prices 16 through 20 is: $38.80
Stock 2
The average for prices 1 through 5 is: $35.45
The average for prices 2 through 6 is: $33.35
The average for prices 3 through 7 is: $33.15
The average for prices 4 through 8 is: $33.85
The average for prices 5 through 9 is: $34.10
The average for prices 6 through 10 is: $35.60
The average for prices 7 through 11 is: $36.50
The average for prices 8 through 12 is: $36.40
The average for prices 9 through 13 is: $35.65
The average for prices 10 through 14 is: $36.20
The average for prices 11 through 15 is: $35.50
The average for prices 12 through 16 is: $36.35
The average for prices 13 through 17 is: $36.45
The average for prices 14 through 18 is: $37.05
The average for prices 15 through 19 is: $37.20
The average for prices 16 through 20 is: $37.80
==============================================
I have been trying to get the decimals to line up so the output looks cleaner. Like maybe shift the first 5 lines to the right 2 spaces, then shift the next 4 lines over to the right 1 spaces and leave the remaining lines there. That way, the decimals are all lined up. Not sure if this was possible without a lot of code. I am not sure if the other results are correct because if the last one isnt correct, than I'm not very sure the others are. I appreciate your help again. You definitely know your C programming. Have a great day!! Tommy