0% found this document useful (0 votes)
13 views

C Style Simple Calculator Using Switch Case

The document describes a simple calculator program that uses a switch statement to perform basic math operations like addition, subtraction, multiplication and division on two operands entered by the user.

Uploaded by

Animal Cares
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

C Style Simple Calculator Using Switch Case

The document describes a simple calculator program that uses a switch statement to perform basic math operations like addition, subtraction, multiplication and division on two operands entered by the user.

Uploaded by

Animal Cares
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Simple Calculator using switch Statement

#include <stdio.h>

int main() {

char op;
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);

switch (op) {
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
// operator doesn't match any case constant
default:
printf("Error! operator is not correct");
}

return 0;
}

You might also like