|
|
@ -1,6 +1,14 @@ |
|
|
|
#include "CreateCustomer.h" |
|
|
|
#include "CustomerProperties.h" |
|
|
|
|
|
|
|
int main() |
|
|
|
{ |
|
|
|
collectCustomerProperties(); |
|
|
|
} |
|
|
|
|
|
|
|
int generateID() |
|
|
|
{ |
|
|
|
srand(time(0)); |
|
|
|
const int MIN = 1000000, MAX = 10000000; |
|
|
|
int p_val = rand() % (MAX); |
|
|
|
if(p_val<MIN) |
|
|
@ -9,3 +17,68 @@ int generateID() |
|
|
|
} |
|
|
|
return p_val; |
|
|
|
} |
|
|
|
|
|
|
|
void collectCustomerProperties() |
|
|
|
{ |
|
|
|
customer_t instance; |
|
|
|
instance.forename = calloc(15+1,sizeof(char)); |
|
|
|
instance.surname = calloc(15+1,sizeof(char)); |
|
|
|
instance.password = calloc(20+1,sizeof(char)); |
|
|
|
instance.ID = generateID(); |
|
|
|
int letterCounter = 0; |
|
|
|
int letterMaximum = 15; |
|
|
|
char userInput=' '; |
|
|
|
bool inputTooLong = false; |
|
|
|
printf("To create a new user, enter the information required below.\n"); |
|
|
|
printf("Enter forename (max. 15 letters):\n"); |
|
|
|
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){ |
|
|
|
*(instance.forename+letterCounter) = userInput; |
|
|
|
++letterCounter; |
|
|
|
if(letterCounter>=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 && (userInput=getchar())!='\n'){ |
|
|
|
*(instance.surname+letterCounter) = userInput; |
|
|
|
++letterCounter; |
|
|
|
if(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 && (userInput=getchar())!='\n'){ |
|
|
|
*(instance.password+letterCounter) = userInput; |
|
|
|
++letterCounter; |
|
|
|
if(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); |
|
|
|
} |