Browse Source

Call to errorMessage() with error code -12 in collectCustomerProperties if the user enters too many digits for the account balance.

remotes/origin/development
fdai7057 2 years ago
parent
commit
1d49c20634
  1. 8
      src/createCustomer.c
  2. 5
      src/error.c

8
src/createCustomer.c

@ -77,18 +77,16 @@ void collectCustomerProperties()
printf("Enter balance (max. 10 digits):\n"); printf("Enter balance (max. 10 digits):\n");
char *balanceCharacters = calloc(10+1+1+1,sizeof(char)); char *balanceCharacters = calloc(10+1+1+1,sizeof(char));
letterMaximum = 10; letterMaximum = 10;
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){
while(letterCounter<=letterMaximum && (userInput=getchar())!='\n'){
*(balanceCharacters+letterCounter) = userInput; *(balanceCharacters+letterCounter) = userInput;
++letterCounter; ++letterCounter;
if(letterCounter>=letterMaximum){
if(letterCounter>letterMaximum){
inputTooLong = true; inputTooLong = true;
break; break;
} }
} }
if(inputTooLong){ if(inputTooLong){
puts("Input too long.");
exit(-1);
//call errorMessage(-10);
errorMessage(-12);
}else{ }else{
if(!foundComma){ if(!foundComma){
*(balanceCharacters+letterCounter) = '.'; *(balanceCharacters+letterCounter) = '.';

5
src/error.c

@ -55,6 +55,11 @@ int errorMessage(int errorCode)
returnValue = -11; returnValue = -11;
exit(-1); exit(-1);
break; break;
case -12:
puts("You entered too many digits.");
returnValue = -12;
exit(-1);
break;
default: default:
puts("Error code unknown."); puts("Error code unknown.");
} }

Loading…
Cancel
Save