]> git.sur5r.net Git - c128-kasse/commitdiff
implement depositing when the user cannot purchase an item
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 29 Sep 2012 15:10:48 +0000 (17:10 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 29 Sep 2012 15:10:48 +0000 (17:10 +0200)
include/credit_manager.h
src/credit_manager.c
src/kasse.c

index 60eea81968c2b49bee2a7f24196aa66b47a7241f..c5dfb99363d1cdb6ed2769cb0c541569de18d39a 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef CREDIT_MANAGER_H_
 #define CREDIT_MANAGER_H_
 struct credits_t *find_credit(char *name);
+void deposit_credit();
 void credit_manager();
 #endif
index ac6fb0a3c379bac8718661a17a9009e693f20303..277df54d43320662f214024f32733a0a79f69359 100644 (file)
@@ -52,20 +52,22 @@ struct credits_t *find_credit(char *name){
 }
 
 /*
- * when depositing money with this and returning to the main menu, the program
- * will crash with a message like the following:
+ * Deposits credit for a user. Called in the credit manager (with input ==
+ * NULL) or interactively when the user does not have enough money for his
+ * intended purchase (with input == nickname).
  * 
  */
-static void deposit_credit() {
+void deposit_credit(char *input) {
        char *time = get_time();
-       char *input;
        struct credits_t *credit;
        unsigned int deposit;
 
-       cprintf("\r\nName:\r\n");
-       if ((input = get_input()) == NULL || *input == '\0')
-               return; // no name given
-               
+       if (input == NULL) {
+               cprintf("\r\nName:\r\n");
+               if ((input = get_input()) == NULL || *input == '\0')
+                       return; // no name given
+       }
+
        if ((credit = find_credit(input)) == NULL)
                return; // cannot find named credit
        
@@ -163,7 +165,7 @@ void credit_manager(){
                                        current_credits_page--;
                                break;
                        case 'p':
-                               deposit_credit(); break;
+                               deposit_credit(NULL); break;
                        case 'g':
                                cprintf("Filter eingeben:\r\n");
                                filter = get_input();
index 5c0ddb9389735dc0cb4da17a4c514e65e57e44d9..40bfbf5fb3b91d3f928df968ce73273db31e6b3d 100644 (file)
@@ -151,10 +151,14 @@ static signed int buy(char *name, unsigned int price) {
                 * to NULL if no such credit could be found */
                credit = find_credit(nickname);
                if (credit != NULL) {
-                       if ((signed int)credit->credit < ((signed int)price * einheiten)) {
-                               cprintf("Sorry, %s hat nicht genug Geld :-(\r\n", nickname);
-                               get_input();
-                               return 0;
+                       while ((signed int)credit->credit < ((signed int)price * einheiten)) {
+                               cprintf("%s hat nicht genug Geld. e) einzahlen a) abbruch \r\n", nickname);
+                               c = cgetc();
+                               if (c == 'e') {
+                                       deposit_credit(nickname);
+                               } else {
+                                       return 0;
+                               }
                        }
                        /* substract money */
                        credit->credit -= (price * einheiten);