Menu-driven program using do-while Dry Run in C

Menu-driven program using do-while is an interactive C dry run visualizer from the While programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Menu-driven program using do-while Program Code

#include <stdio.h>
int main() {
    int choice, a, b;
    
    do {
        printf("\n--- MENU ---\n");
        printf("1. Add\n2. Subtract\n3. Multiply\n4. Divide\n5. Exit\n");
        printf("Enter choice: ");
        scanf("%d", &choice);
        
        if(choice >= 1 && choice <= 4) {
            printf("Enter two numbers: ");
            scanf("%d %d", &a, &b);
        }
        
        switch(choice) {
            case 1: printf("Sum = %d\n", a + b); break;
            case 2: printf("Difference = %d\n", a - b); break;
            case 3: printf("Product = %d\n", a * b); break;
            case 4: 
                if(b != 0)
                    printf("Quotient = %.2f\n", (float)a / b);
                else
                    printf("Cannot divide by zero!\n");
                break;
            case 5: printf("Exiting...\n"); break;
            default: printf("Invalid choice!\n");
        }
    } while(choice != 5);
    
    return 0;
}

View the complete While programs page.

Program Console Menu-driven program using do-while Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.