Answered step by step
Verified Expert Solution
Question
1 Approved Answer
My code has a problem where it validates the postal code before the user inputs data thus resulting in the error message triggering it should
My code has a problem where it validates the postal code before the user inputs data thus resulting in the error message triggering it should be just as the corrected output i need some help please. this is coded in C
#define CRTSECURENOWARNINGS
#include
#include
#include
#include
struct Customer
char firstname;
char lastname;
char streetaddress;
char city;
char province;
char postalcode;
;
int isValidPostalCodechar postalcode;
struct Customer getCustomerInfovoid
struct Customer customer;
printfEnter your first name: ;
fgetscustomerfirstname, sizeofcustomerfirstname stdin;
customer.firstnamestrcspncustomerfirstname,
;
while
printfEnter your last name: ;
fgetscustomerlastname, sizeofcustomerlastname stdin;
customer.lastnamestrcspncustomerlastname,
;
if strlencustomerlastname
break;
else
printfInvalid Entry: ;
printfEnter your street address: ;
fgetscustomerstreetaddress, sizeofcustomerstreetaddress stdin;
customer.streetaddressstrcspncustomerstreetaddress,
;
printfEnter your city: ;
fgetscustomercity, sizeofcustomercity stdin;
customer.citystrcspncustomercity,
;
printfEnter your province: ;
fgetscustomerprovince, sizeofcustomerprovince stdin;
customer.provincestrcspncustomerprovince,
;
while
printfEnter your postal code: ;
fgetscustomerpostalcode, sizeofcustomerpostalcode stdin;
customer.postalcodestrcspncustomerpostalcode,
;
if isValidPostalCodecustomerpostalcode
break;
else
printfInvalid Entry: ;
return customer;
int isValidPostalCodechar postalcode
int i;
for i ; i ; i
postalcodei toupperpostalcodei;
if isalphapostalcode && isdigitpostalcode && isalphapostalcode &&
postalcode &&
isdigitpostalcode && isalphapostalcode &&
strlenpostalcode
return ;
else
return ;
int mainvoid
struct Customer customer getCustomerInfo;
printf
You entered:
s s
s
ss
s
customer.firstname, customer.lastname,
customer.streetaddress,
customer.city, customer.province,
customer.postalcode;
return ;
My Output
Enter your first name: John
Enter your last name:
Invalid Entry: Enter your last name: Smith
Enter your street address: Elm St
Enter your city: Toronto
Enter your province: ON
Enter your postal code: Invalid Entry: Enter your postal code: mex
Invalid Entry: Enter your postal code: me x
You entered:
John Smith
Elm St
Toronto, ON
ME X
Program ended with exit code:
Corrected Output
Enter your first name: John
Enter your last name:
Invalid Entry: Enter your last name: Smith
Enter your street address: Elm St
Enter your city: Toronto
Enter your province: ON
Enter your postal code: mex
Invalid Entry: Enter your postal code: me x
You entered:
John Smith
Elm St
Toronto, ON
ME X
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started