Browse Source

implementation of collectCustomerProperties().

remotes/origin/beta
fdai7057 2 years ago
committed by fdai7207
parent
commit
7554c8c24d
  1. 68
      src/CreateCustomer.c
  2. 2
      src/CreateCustomer.h
  3. 8
      src/CustomerProperties.h

68
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<MIN)
@ -9,3 +12,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);
}

2
src/CreateCustomer.h

@ -1,4 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
int generateID();
void collectCustomerProperties();

8
src/CustomerProperties.h

@ -1,5 +1,7 @@
typedef struct Customer{
int ID;
char *forename,*surname,*password;
typedef struct Customer
{
unsigned int ID;
char *password;
char *forename, *surname;
float balance;
}customer_t;
Loading…
Cancel
Save