A simple command-line calculator in C that performs basic arithmetic operations including addition, subtraction, multiplication, and division. The program takes user input for the operator and operands, and displays the result accordingly.
A simple command-line calculator that performs basic arithmetic operations (addition, subtraction, multiplication, division). This program is written in C and demonstrates the use of conditional statements and user input handling.
To check whether MinGW is recognized by your system, use the following command:
gcc -v
use the play button in the top right corner to run and debug the code.
To compile the game, use the following command:
gcc -o Calculator Calculator.c
To run the compiled program:
./Calculator
If you encounter any issues setting up MinGW on Windows, refer to this guide: How to run a C program in Visual Studio Code
Addition (+):
Input:
Enter an operator (+, -, *, /): +
Enter the first number: 2
Enter the second number: 3
Output:
2.00 + 3.00 = 5.00
Subtraction (-):
Input:
Enter an operator (+, -, *, /): -
Enter the first number: 5.5
Enter the second number: 2.2
Output:
5.50 - 2.20 = 3.30
Multiplication (*):
Input:
Enter an operator (+, -, *, /): *
Enter the first number: 4
Enter the second number: 2.5
Output:
4.00 * 2.50 = 10.00
Division (/), Valid Division
Input:
Enter an operator (+, -, *, /): /
Enter the first number: 10
Enter the second number: 2
Output:
10.00 / 2.00 = 5.00
Division (/), Division by Zero
Input:
Enter an operator (+, -, *, /): /
Enter the first number: 10
Enter the second number: 0
Output:
Error! Division by zero.
Invalid Operator
Input:
Enter an operator (+, -, *, /): %
Enter the first number: 10
Enter the second number: 2
Output:
Invalid operator!
Standard C library: