Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

#include 
#include 

bool isLandingGearExtended = false;

void extendLandingGear() {
    if (isLandingGearExtended) {
        printf("Landing gear is already extended.\n");
    } else {
        printf("Extending landing gear...\n");
        // Code to extend the landing gear goes here
        isLandingGearExtended = true;
        printf("Landing gear extended.\n");
    }
}

void retractLandingGear() {
    if (!isLandingGearExtended) {
        printf("Landing gear is already retracted.\n");
    } else {
        printf("Retracting landing gear...\n");
        // Code to retract the landing gear goes here
        isLandingGearExtended = false;
        printf("Landing gear retracted.\n");
    }
}

int main() {
    int choice;

    do {
        printf("Select an option:\n");
        printf("1. Extend landing gear\n");
        printf("2. Retract landing gear\n");
        printf("3. Exit\n");
        printf("Choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                extendLandingGear();
                break;
            case 2:
                retractLandingGear();
                break;
            case 3:
                printf("Exiting...\n");
                break;
            default:
                printf("Invalid choice. Please try again.\n");
                break;
        }

        printf("\n");
    } while (choice != 3);

    return 0;
}
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.