Question: Is there a function that could reduce repetition? Possible with the yesNo ...? void getAddress(struct Address *address) { char yesNo; do { printf(Please enter the

Is there a function that could reduce repetition? Possible with the yesNo ...?

void getAddress(struct Address *address)

{

char yesNo;

do {

printf("Please enter the contact's street number: ");

scanf("%d%*c", &address->streetNumber);

} while (address->streetNumber < 1);

printf("Please enter the contact's street name: ");

scanf("%40[^ ]%*c", address->street);

printf("Do you want to enter an apartment number? (y or n): ");

scanf("%c%*c", &yesNo);

if (yesNo == 'y' || yesNo == 'Y') { // change to single quotes

do {

printf("Please enter the contact's apartment number: ");

scanf("%d%*c", &address->apartmentNumber);

} while (address->apartmentNumber < 1);

}

printf("Please enter the contact's postal code: ");

scanf("%7[^ ]%*c", address->postalCode);

printf("Please enter the contact's city: ");

scanf("%40[^ ]%*c", address->city);

}

void getNumbers(struct Numbers *numbers)

{

char yesNo;

printf("Do you want to enter a cell phone number? (y or n): ");

scanf("%c%*c", &yesNo);

if (yesNo == 'y' || yesNo == 'Y') {

printf("Please enter the contact's cell phone number: ");

scanf("%10[^ ]%*c", numbers->cell);

}

printf("Do you want to enter a home phone number? (y or n): ");

scanf("%c%*c", &yesNo);

if (yesNo == 'y' || yesNo == 'Y') { // change && to ||

printf("Please enter the contact's home phone number: ");

scanf("%10[^ ]%*c", numbers->home);

}

printf("Do you want to enter a business phone number? (y or n): ");

scanf("%c%*c", &yesNo);

if (yesNo == 'y' || yesNo == 'Y') {

printf("Please enter the contact's business phone number: ");

scanf("%10[^ ]%*c", numbers->business);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!