Answers for "Write a Simple Calculator Using If Else Statement that prompts the user to Input two Numbers. Then it will Display the Menu for Addition, Subtraction, Multiplication, Division, Square of 1st Number, Cube of 1st. After any choice it will Display the Answer"

C
1

c calculator program

#include <stdio.h>
int main() {
    char operator;
    double first, second;
    printf("Enter an operator (+, -, *,): ");
    scanf("%c", &operator);
    printf("Enter two operands: ");
    scanf("%lf %lf", &first, &second);

    switch (operator) {
    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;
}
Posted by: Guest on November-10-2020

Code answers related to "Write a Simple Calculator Using If Else Statement that prompts the user to Input two Numbers. Then it will Display the Menu for Addition, Subtraction, Multiplication, Division, Square of 1st Number, Cube of 1st. After any choice it will Display the Answer"

Code answers related to "C"

Browse Popular Code Answers by Language