/*This is the eighth lab of Lab EE107
The purpose of this lab understand how a program (using if-else) that identify the operator used
and print out the result.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: March 19th, 2024.
    */
#include <stdio.h>

int main() {
    // Declare variables to store the numbers and operator
    float num1_EU, num2_EU;
    char operator_EU;

    // Prompt the user to enter the expression
    printf("Enter expression (number operator number): \n");

    // Read the input expression from the user
    scanf("%f %c %f", &num1_EU, &operator_EU, &num2_EU);

    // Check the operator and perform the corresponding operation
    if (operator_EU == '+') {
        printf("%.2f + %.2f = Result: %.2f\n", num1_EU, num2_EU, num1_EU + num2_EU);
    } else if (operator_EU == '-') {
        printf("%.2f - %.2f = Result: %.2f\n", num1_EU, num2_EU, num1_EU - num2_EU);
    } else if (operator_EU == '*') {
        printf("%.2f * %.2f = Result: %.2f\n", num1_EU, num2_EU, num1_EU * num2_EU);
    } else if (operator_EU == '/') {
        // Check for division by zero
        if (num2_EU == 0) {
            printf("Error: Division by zero\n");
        } else {
            printf("%.2f / %.2f = Result: %.2f\n", num1_EU, num2_EU, num1_EU / num2_EU);
        }
    } else {
        // Handle invalid operator
        printf("Error: Invalid operator\n");
    }

    return 0;
}


Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: