]> git.sur5r.net Git - c128-kasse/blob - kasse.c
extern var
[c128-kasse] / kasse.c
1 #include <stdio.h>
2 #include <conio.h>
3 #include <stdlib.h>
4
5 #include "config.h"
6 #include "kasse.h"
7 // conf
8 // drucker 4 oder 5
9 // pricee+getraenke
10 //
11 // graphic 4,0,10
12
13
14
15 /* Hauptbildschirm ausgeben */
16 void print_screen() {
17         uc i = 0;
18         clrscr();
19         printf("C128-Kassenprogramm\n\n");
20         printf("Eingenommen: %d Euro, Verkauft: %d Flaschen\n\n", money * 100, items_sold);
21         for (; i < num_items; ++i)
22                 printf("Item %x: %s (%d Cents, %d mal verkauft)\n", i, status[i].item_name, status[i].price, status[i].times_sold);
23         printf("\nBefehle: s) Save Data\n");
24 }
25
26 /* Wird ausgelagert */
27 void save_data() {
28 }
29
30 void buy(uc n) {
31         int negative = 1;
32         char entered[5] = {49, 0, 0, 0, 0};
33         uc i = 0;
34         uc c;
35         int einheiten;
36         if (status[n].item_name == NULL)
37                 printf("ERROR: No such item\n");
38         else {
39                 printf("Wieviel Einheiten \"%s\"?\n", status[n].item_name);
40                 while (1) {
41                         c = getchar();
42                         if (c == 13)
43                                 break;
44                         else if (c == 45 && i == 0)
45                                 negative = -1;
46                         else if (c > 47 && c < 58)
47                                 entered[i++] = c;
48                 }
49                 einheiten = atoi(entered) * negative;
50                 status[n].times_sold += einheiten;
51                 money += status[n].price * einheiten;
52                 items_sold += einheiten;
53         }
54 }
55
56 int main() {
57         static uc c;
58         /* TODO: remove */
59         status[0].item_name = "cola";
60         status[0].price = 230;
61         status[0].times_sold = 0;
62         status[1].item_name = "mate";
63         status[1].price = 150;
64         status[0].times_sold = 0;
65         for (c = 2; c < MAX_ITEMS; ++c)
66                 status[c].item_name = NULL;
67         while (1) {
68                 /* Bildschirm anzeigen */
69                 print_screen();
70                 /* Tastatureingaben abfragen */
71                 c = getchar();
72                 /* und eventuell weitere Dialoge anzeigen */
73                 if (c > 47 && c < 58)
74                         buy(c - 48);
75                 else if (c == 115)
76                         save_data();
77                 else if (c == 113)
78                         break;
79         }
80         printf("BYEBYE\n");
81 }