![]() |
|
#1
|
|||
|
|||
Can someone check to see if my program is correctI finally finished this program and some of the answers I am getting aren't correct and I don't know why. For example, Report 4 states:
The number of days in which the moving average of stock1 exceeded the moving ave rage of stock2: 10 days The number of days in which the moving average of stock2 exceeded the moving ave rage of stock1: 6 days The moving average of stock1 equals the moving average of stock2: 0 days I know the last one is incorrect because for stock1, the 16 five-day average for 2-6 is: $35.50 and for stock2, the average price from 11-15 is: $35.50. The answer should be 1 and not 0. I don't know why I am getting an answer of 0. One last thing......The output for the 16 five-day moving averages. Can the output for Report 3 look any better? I tried using %10.2f and but since it's in a loop, the changes effect everything that's printed within that loop. I have my own header file and that's why I have PrintDate(); and PauseScreen();, If the code can be improved, please let me know. Thanks for any help. CPP / C++ / C Code:
Report 1 Apr 12 2004 ******** Scott's Trading Company----------------------- Stock1 has exceeded the price of stock2 by: 9 days Stock2 has exceeded the price of stock1 by: 11 days The number of days in which the price of the stocks were the same: 0 days Please press any key to continue ================================================== ======== Report 2 Apr 12 2004 ******** The number of days in which stock1 exceeded it's average price: 10 days The number of days in which stock2 exceeded it's average price: 12 days Please press any key to continue ================================================== ======== 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 Please press any key to continue ================================================== ======== Report 4 Apr 12 2004 ******** The number of days in which the moving average of stock1 exceeded the moving ave rage of stock2: 10 days The number of days in which the moving average of stock2 exceeded the moving ave rage of stock1: 6 days The moving average of stock1 equals the moving average of stock2: 0 days Please press any key to continue ================================================== ======== Last edited by dsmith : 12-Apr-2004 at 17:30.
Reason: Use [c] & [/c] for syntax highlighting (not [code])
|
|
#2
|
||||
|
||||
|
CPP / C++ / C Code:
in this function, youre actually comparing movAvg1 and movAvg2 according to their index, that means youre comparing moveAvg1[0] with moveAvg2[0], but not comparing moveAvg1[0] with moveAvg2[1] and so on. That's why you got 0 for "The moving average of stock1 equals the moving average of stock2: 0 days" Although I don't get what you are doing, I sense that this maybe the problem and I suggest you to use two for loop to compare all the item. __________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#3
|
|||
|
|||
|
Thank Max. I used two for loops and I got a 1 for the answer, which is correct. I appreciate your help. What I have done is calculated a 16 five-day moving average on stock1 and stock2. I have 20 prices for each stock. Once I calculated the 16 five-day moving averages, I put these in an array named movingAvg1 and movingAvg2. So, with the 2 for loops, I am comparing the index of movingAvg1 with the index of movingAvg2. Thanks again.....
![]() |
Recent GIDBlog
Developing GUIs with wxPython (Part 2) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Modify a C program | ayoub | C Programming Language | 3 | 15-Mar-2004 11:34 |
| error during program | rjd72285 | C++ Forum | 0 | 11-Nov-2003 18:49 |
| one program access another? | dgoulston | C++ Forum | 1 | 07-Oct-2003 11:26 |
| Attention Resellers! Check this program out! | Yippee | Web Hosting Advertisements & Offers | 0 | 22-Jul-2003 09:05 |
| Attention Resellers! Check this program out! | Yippee | Web Hosting Advertisements & Offers | 1 | 12-Jul-2003 18:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The