From 7554c8c24dbf027fecbfe546b87835a44e55f438 Mon Sep 17 00:00:00 2001 From: fdai7057 Date: Fri, 20 Jan 2023 10:42:35 +0100 Subject: [PATCH] implementation of collectCustomerProperties(). --- src/CreateCustomer.c | 68 ++++++++++++++++++++++++++++++++++++++++ src/CreateCustomer.h | 2 ++ src/CustomerProperties.h | 10 +++--- 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/CreateCustomer.c b/src/CreateCustomer.c index 26bf617..41696d8 100644 --- a/src/CreateCustomer.c +++ b/src/CreateCustomer.c @@ -1,6 +1,9 @@ #include "CreateCustomer.h" +#include "CustomerProperties.h" + int generateID() { + srand(time(0)); const int MIN = 1000000, MAX = 10000000; int p_val = rand() % (MAX); if(p_val=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + printf("Forename too long. Aborting.\n"); + exit(-1); + }else{ + *(instance.forename+letterCounter) = '\0'; + letterCounter = 0; + } + printf("Enter surname (max. 15 letters):\n"); + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + printf("Surname too long. Aborting.\n"); + exit(-1); + }else{ + *(instance.surname+letterCounter) = '\0'; + letterCounter = 0; + } + printf("Enter password (max. 20 letters):\n"); + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + printf("Password too long. Aborting.\n"); + exit(-1); + } + *(instance.password+letterCounter) = '\0'; + letterCounter = 0; + printf("Enter balance:\n"); + scanf("%f",&instance.balance); + + printf("Account successfully created. Your ID is: %d. Note it somewhere!\n",instance.ID); +} diff --git a/src/CreateCustomer.h b/src/CreateCustomer.h index add2b60..cb425a1 100644 --- a/src/CreateCustomer.h +++ b/src/CreateCustomer.h @@ -1,4 +1,6 @@ #include #include +#include #include int generateID(); +void collectCustomerProperties(); diff --git a/src/CustomerProperties.h b/src/CustomerProperties.h index e2ba317..0463c2d 100644 --- a/src/CustomerProperties.h +++ b/src/CustomerProperties.h @@ -1,5 +1,7 @@ -typedef struct Customer{ - int ID; - char *forename,*surname,*password; - float balance; +typedef struct Customer +{ + unsigned int ID; + char *password; + char *forename, *surname; + float balance; }customer_t;