Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions