aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2015-05-20 20:34:02 -0400
committerFranklin Wei <git@fwei.tk>2015-05-20 20:34:02 -0400
commit28ff4aa610c6c98645973ed4fc9acb6cc7a0cf30 (patch)
tree6d66040c89faf785b20c82c6edfbe5e0e68450e8
parent617b7ca872037b90cf5a758f7a10fcf3a5840616 (diff)
downloadmarket-sim-28ff4aa610c6c98645973ed4fc9acb6cc7a0cf30.zip
market-sim-28ff4aa610c6c98645973ed4fc9acb6cc7a0cf30.tar.gz
market-sim-28ff4aa610c6c98645973ed4fc9acb6cc7a0cf30.tar.bz2
market-sim-28ff4aa610c6c98645973ed4fc9acb6cc7a0cf30.tar.xz
some stuff
-rw-r--r--README.md2
-rw-r--r--src/info.c8
-rw-r--r--src/util.c22
3 files changed, 23 insertions, 9 deletions
diff --git a/README.md b/README.md
index d5f5863..7e0d13e 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
Market-Sim
==========
-A market simulator
+A stock market simulation game
diff --git a/src/info.c b/src/info.c
index e8d0102..bde4bf4 100644
--- a/src/info.c
+++ b/src/info.c
@@ -15,8 +15,16 @@ void info_handler(struct player_t *player)
return;
}
+ printf("Updating price data...\n");
+ if(!get_stock_info(sym, &stock->current_price, &stock->fullname))
+ {
+ printf("Failed to update prices.\n");
+ return;
+ }
+
free(sym);
+
printf("Transaction history for '%s':\n", stock->symbol);
printf("================================================================================\n");
print_history(stock);
diff --git a/src/util.c b/src/util.c
index eccdef5..8cd197d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -194,12 +194,15 @@ void print_handler(struct player_t *player)
for(uint i = 0; i < player->portfolio_len; ++i)
{
struct stock_t *stock = player->portfolio + i;
- ullong total_value = stock->count * stock->current_price.cents;
- printf("%6s %40s %5llu * $%5llu.%02llu = $%6llu.%02llu\n",
- stock->symbol, stock->fullname, stock->count, stock->current_price.cents / 100, stock->current_price.cents % 100,
- total_value / 100, total_value % 100);
-
- portfolio_value += stock->current_price.cents * stock->count;
+ if(stock->count)
+ {
+ ullong total_value = stock->count * stock->current_price.cents;
+ printf("%6s %40s %5llu * $%5llu.%02llu = $%6llu.%02llu\n",
+ stock->symbol, stock->fullname, stock->count, stock->current_price.cents / 100, stock->current_price.cents % 100,
+ total_value / 100, total_value % 100);
+
+ portfolio_value += stock->current_price.cents * stock->count;
+ }
}
}
printf("================================================================================\n");
@@ -247,8 +250,11 @@ void update_handler(struct player_t *player)
for(uint i = 0; i < player->portfolio_len; ++i)
{
struct stock_t *stock = player->portfolio + i;
- printf("%s...\n", stock->symbol);
- get_stock_info(stock->symbol, &stock->current_price, &stock->fullname);
+ if(stock->count > 0)
+ {
+ printf("%s...\n", stock->symbol);
+ get_stock_info(stock->symbol, &stock->current_price, &stock->fullname);
+ }
}
}