Update index.md (#27111)
This commit is contained in:
committed by
Christopher McCormack
parent
07ae8e2985
commit
3cee0f4afb
@ -45,26 +45,26 @@ Using a switch statement over multiple if/else statements can contribute to more
|
|||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
char operator;
|
char operator;
|
||||||
double firstNumber,secondNumber;
|
double a, b;
|
||||||
|
|
||||||
printf("Enter an operator (+, -, *, /): ");
|
printf("Enter an operator (+, -, *, /): ");
|
||||||
scanf("%c", &operator);
|
scanf("%c", &operator);
|
||||||
|
|
||||||
printf("Enter two operands: ");
|
printf("Enter two operands: ");
|
||||||
scanf("%lf %lf",&firstNumber, &secondNumber);
|
scanf("%lf %lf",&a, &b);
|
||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case '+':
|
case '+':
|
||||||
printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber+secondNumber);
|
printf("%.1lf + %.1lf = %.1lf", a, b, a+b);
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber-secondNumber);
|
printf("%.1lf - %.1lf = %.1lf",a, b, a-b);
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber*secondNumber);
|
printf("%.1lf * %.1lf = %.1lf",a, b, a*b);
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber/firstNumber);
|
printf("%.1lf / %.1lf = %.1lf",a, b, a/b);
|
||||||
break;
|
break;
|
||||||
// Operator is doesn't match any case constant (+, -, *, /)
|
// Operator is doesn't match any case constant (+, -, *, /)
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user