Click here to Skip to main content
15,911,132 members
Home / Discussions / C#
   

C#

 
GeneralRe: Character conversion in .NET Pin
Paul Selormey11-Jan-05 5:46
Paul Selormey11-Jan-05 5:46 
GeneralRe: Character conversion in .NET Pin
Heath Stewart11-Jan-05 7:14
protectorHeath Stewart11-Jan-05 7:14 
GeneralRe: Character conversion in .NET Pin
Paul Selormey11-Jan-05 11:30
Paul Selormey11-Jan-05 11:30 
GeneralGet access to an object during runtime from its process Pin
Dany McCarthy10-Jan-05 13:42
Dany McCarthy10-Jan-05 13:42 
GeneralRe: Get access to an object during runtime from its process Pin
Heath Stewart10-Jan-05 20:01
protectorHeath Stewart10-Jan-05 20:01 
GeneralRe: Get access to an object during runtime from its process Pin
Dany McCarthy11-Jan-05 14:50
Dany McCarthy11-Jan-05 14:50 
GeneralStock Market Simulation Pin
8raker10-Jan-05 13:00
8raker10-Jan-05 13:00 
GeneralRe: Stock Market Simulation Pin
Colin Angus Mackay10-Jan-05 13:46
Colin Angus Mackay10-Jan-05 13:46 
Well, the easiest way is to take the problem and break it into smaller problems, then work on the smaller problems. If you still can't work it out then perhaps the problem is still too big and needs to be broken down further.

So your user has:
money
choice of stocks
ownership of stock

The program runs for 30 cycles (days). In each cycle the user has the option to buy or sell stock. (I suggest allowing the user to sell first, before buying). At the end of each cycle the each stock price changes by a random amount (to simulate market movements)


At the start of your program you need to set up the variables (money, stocks, and owenership).

You may wish to look at NameObjectCollection[^] so you can create a look up based on the stock name. So you have a lookup of stocks (the key is the stock name) with the object being the current stock price. The same goes for ownership (the key is the stock name, with the object being the current quantity of stock owned) [Is this making any sense? If I'm talking at the wrong level let me know]

Each cycle you get the user input for the stocks they wish to sell. You adjust the ownership list for these stocks by the amount of stock they sell and credit the money they have with the sale price.

You then allow the user to buy stock. Add the stock to ownership list, and deduct the amout of money it cost from their account.

At the end of the program you can list how much money the user has, and how much of each stock (and the value of each, if you want).

I hope this has helped. It may help if you write out some pseudo code (a kind of English-like code that reads like bullet points on paper) that can help to organise thoughts better. Like this:

--Initial setup
* Set money to $1000
* Set stock_price item "MSFT" to $25
* Set stock_price item "RYA" to $36
* Set stock_price item "HBOS" to $12
* Set ownership item "MSFT" to $0
* Set ownership item "RYA" to $0
* Set ownership item "HBOS" to $0
-- Main loop
* Loop 30 times
-- Sell Stock
** Ask for stock to sell
** Get stock_name as input
** Get quantity as input
** Subtract quantity from ownership item [stock_name]
** Add quantity * stock_price [stock_name] to money
-- Buy Stock
** Ask for stock to buy
** Get stock_name as input
** Get quantity as input
** Add quantity from ownership item [stock_name]
** Subtract quantity * stock_price [stock_name] from money
-- Update stock prices
** Change stock_price "MSFT" by random amount
** Change stock_price "RYA" by random amount
** Change stock_price "HBOS" by random amount
* End loop
* Display results

You can use what ever notation works for you. What ever way helps you organise your thoughts...

Does this help?


Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums


Upcoming talk:
SELECT UserName, Password FROM Users
-- Getting unauthorised access to a SQL Server, and how to prevent it.

GeneralRe: Stock Market Simulation Pin
8raker11-Jan-05 1:17
8raker11-Jan-05 1:17 
GeneralRe: Stock Market Simulation Pin
Colin Angus Mackay11-Jan-05 1:52
Colin Angus Mackay11-Jan-05 1:52 
GeneralSyncronize Windows Forms DataGrid with DataSet Pin
epinaud10-Jan-05 11:01
epinaud10-Jan-05 11:01 
GeneralRe: Syncronize Windows Forms DataGrid with DataSet Pin
Heath Stewart10-Jan-05 19:54
protectorHeath Stewart10-Jan-05 19:54 
Generalproblem in opening a web application project Pin
panky_710-Jan-05 10:56
panky_710-Jan-05 10:56 
GeneralRe: problem in opening a web application project Pin
panky_710-Jan-05 12:02
panky_710-Jan-05 12:02 
GeneralRe: problem in opening a web application project Pin
Heath Stewart10-Jan-05 20:03
protectorHeath Stewart10-Jan-05 20:03 
GeneralRe: Missing / searching 2nd DataItem as independant index in list/combobox Pin
Rob Graham10-Jan-05 10:56
Rob Graham10-Jan-05 10:56 
GeneralDeleting a Row from a DataSet in a DataGrid Pin
joschmo8010-Jan-05 9:08
joschmo8010-Jan-05 9:08 
GeneralRe: Deleting a Row from a DataSet in a DataGrid Pin
DougW4810-Jan-05 15:36
DougW4810-Jan-05 15:36 
GeneralRe: Deleting a Row from a DataSet in a DataGrid Pin
Heath Stewart10-Jan-05 20:09
protectorHeath Stewart10-Jan-05 20:09 
GeneralRe: Deleting a Row from a DataSet in a DataGrid Pin
joschmo8011-Jan-05 1:56
joschmo8011-Jan-05 1:56 
GeneralAccess Security for window based Pin
caheo10-Jan-05 8:48
caheo10-Jan-05 8:48 
GeneralRe: Access Security for window based Pin
Heath Stewart10-Jan-05 20:14
protectorHeath Stewart10-Jan-05 20:14 
QuestionHow to create a typed DataSet at run-time without type definition files (.xsd or .dtd)? Pin
huckfinn10-Jan-05 7:30
huckfinn10-Jan-05 7:30 
Generalcomparing arrays Pin
sciamachy10-Jan-05 6:50
sciamachy10-Jan-05 6:50 
GeneralRe: comparing arrays Pin
Judah Gabriel Himango10-Jan-05 8:01
sponsorJudah Gabriel Himango10-Jan-05 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.