From 37010e9b9dd2b36ff5204ee6194757277acc972b Mon Sep 17 00:00:00 2001 From: sECuRE Date: Sat, 28 Jul 2007 17:13:13 +0000 Subject: [PATCH] fix git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@9 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- config.h | 4 ++-- kasse.c | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/config.h b/config.h index a90230e..6838e83 100644 --- a/config.h +++ b/config.h @@ -17,8 +17,8 @@ struct status_t { unsigned int times_sold; }; -#define MAX_ITEMS 16 -static struct status_t status[MAX_ITEMS]; +#define MAX_ITEMS 15 +static struct status_t status[MAX_ITEMS+1]; // unklar bis jetzt was das tun wird void load_config(); diff --git a/kasse.c b/kasse.c index e423bd9..8112a5a 100644 --- a/kasse.c +++ b/kasse.c @@ -6,7 +6,7 @@ #include "kasse.h" // conf // drucker 4 oder 5 -// preise+getraenke +// pricee+getraenke // // graphic 4,0,10 @@ -17,7 +17,7 @@ void print_screen() { uc i = 0; clrscr(); printf("C128-Kassenprogramm\n\n"); - printf("Eingenommen: 1337 Euro, Verkauft: 42 Flaschen\n\n"); + printf("Eingenommen: %d Euro, Verkauft: %d Flaschen\n\n", money * 100, items_sold); for (; i < num_items; ++i) printf("Item %x: %s (%d Cents, %d mal verkauft)\n", i, status[i].item_name, status[i].price, status[i].times_sold); printf("\nBefehle: s) Save Data\n"); @@ -28,20 +28,25 @@ void save_data() { } void buy(uc n) { - static uc einheiten = 1; - static uc c; + int negative = 1; + char entered[5] = {49, 0, 0, 0, 0}; + uc i = 0; + uc c; + int einheiten; if (status[n].item_name == NULL) printf("ERROR: No such item\n"); else { printf("Wieviel Einheiten \"%s\"?\n", status[n].item_name); while (1) { c = getchar(); - printf("das war %x\n", c); - if (c == 32) + if (c == 13) break; - else if (c > 47 && c < 60) - einheiten += (c - 48); + else if (c == 45 && i == 0) + negative = -1; + else if (c > 47 && c < 58) + entered[i++] = c; } + einheiten = atoi(entered) * negative; status[n].times_sold += einheiten; money += status[n].price * einheiten; items_sold += einheiten; @@ -57,7 +62,7 @@ int main() { status[1].item_name = "mate"; status[1].price = 150; status[0].times_sold = 0; - for (c = 2; c < 15; ++c) + for (c = 2; c < MAX_ITEMS; ++c) status[c].item_name = NULL; while (1) { /* Bildschirm anzeigen */ @@ -65,7 +70,7 @@ int main() { /* Tastatureingaben abfragen */ c = getchar(); /* und eventuell weitere Dialoge anzeigen */ - if (c > 47 && c < 60) + if (c > 47 && c < 58) buy(c - 48); else if (c == 115) save_data(); -- 2.39.2