C PROGRAMMING PROGRAM • SWITCH & MENU PROGRAMS

Create a Temperature Converter Menu Using switch

Learn how to create a temperature converter menu using switch using a clear C program.

BeginnerswitchUnit conversionMenu

PROBLEM UNDERSTANDING

Input and expected output

Sample input
1
25
Sample output
Fahrenheit = 77.00

COMPLETE C PROGRAM

Complete C implementation

switch-temperature-converter.c
Open in compiler
#include <stdio.h>

int main(void)
{
    int choice;
    double value;
    printf("1. Celsius to Fahrenheit\n2. Fahrenheit to Celsius\nChoose: ");
    scanf("%d", &choice);
    printf("Enter temperature: ");
    scanf("%lf", &value);
    switch (choice) {
        case 1: printf("Fahrenheit = %.2f\n", value * 9.0 / 5.0 + 32.0); break;
        case 2: printf("Celsius = %.2f\n", (value - 32.0) * 5.0 / 9.0); break;
        default: puts("Invalid choice.");
    }
    return 0;
}

GUIDED CODE TOUR • NOT LIVE EXECUTION

Study the program line by line

Use the real compiler button above to run and debug with different inputs.

CURRENT STEP

Select Start to walk through the important lines.

SELECTED LINE

No line selected

EXPECTED OUTPUT FOR THE SAMPLE

Fahrenheit = 77.00
0%Step 0 of 0

PROGRAM EXPLANATION

Algorithm and explanation

  1. Read the required input values.
  2. Use the menu choice to select one of the two temperature-conversion formulas.
  3. Display the computed result.

Use the menu choice to select one of the two temperature-conversion formulas.

EFFICIENCY

Time and space complexity

Time complexity

O(1)

Auxiliary space

O(1)

DEBUGGING CHECKLIST

Common mistakes

Check this

Use the correct format specifier for every variable.

Check this

Initialize variables before using their values.

Check this

Check braces, semicolons and input order carefully.

Try it yourself

Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.