Skip to content

VedantPadole52/Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Here’s a README file for your simple calculator program:


Simple Calculator - README

Overview

This program is a basic command-line calculator that performs simple arithmetic operations such as addition, subtraction, multiplication, and division. The user is prompted to enter an operator and two numbers, and the program then displays the result of the calculation.

Features

  • Addition (+), Subtraction (-), Multiplication (*), Division (/).
  • Handles division by zero with an error message.
  • Validates operator input and provides an error message for invalid operators.

File Structure

  • main.c: The source code for the calculator.

Prerequisites

  • C Compiler: The program is written in C, so a C compiler like GCC is required to compile the program.
  • Operating System: The program works on any platform where a C compiler is available.

How to Compile and Run

Step 1: Install a C Compiler

If you don't already have a C compiler, here’s how you can install one:

  • Windows: You can use MinGW, or use an IDE like Code::Blocks.
  • Linux: Install GCC using sudo apt-get install build-essential on Debian-based systems (or the equivalent package manager for other distributions).
  • macOS: Install Xcode Command Line Tools with the command xcode-select --install.

Step 2: Download/Clone the Project

If you don't already have the code, download or clone the repository containing main.c.

git clone <repository_url>

Step 3: Navigate to the Project Directory

Navigate to the folder containing main.c using the terminal or command prompt.

Step 4: Compile the Code

Run the following command to compile the code:

gcc -o calculator main.c

This will create an executable file named calculator.

Step 5: Run the Program

To run the program, use the following command:

  • On Linux/macOS:
    ./calculator
  • On Windows:
    calculator.exe

Step 6: Follow the On-Screen Instructions

Once the program is running, follow the instructions to input:

  • An operator (+, -, *, /).
  • Two numbers on which to perform the calculation.

The result will be displayed immediately after the input.

How the Program Works

  1. Enter an Operator:

    • The user is asked to input one of the following operators:
      • + for addition
      • - for subtraction
      • * for multiplication
      • / for division
  2. Enter Two Numbers:

    • The user enters two numeric values, separated by a comma (e.g., 5.5, 2).
  3. Perform the Calculation:

    • The program performs the selected operation and displays the result.
  4. Error Handling:

    • If the user tries to divide by zero, the program will output an error message: Error: Division by zero.
    • If the user enters an invalid operator, the program will display an error message: Error: Invalid operator.

Sample Output

Here’s a sample of what the program might look like when running:

Enter an operator (+, -, *, /): +
Enter two numbers: 12.5, 8
Result is 20.50

Another example:

Enter an operator (+, -, *, /): /
Enter two numbers: 10, 0
Error: Division by zero

And an invalid operator example:

Enter an operator (+, -, *, /): ^
Error: Invalid operator

Limitations

  • The program only supports the basic four arithmetic operations: addition, subtraction, multiplication, and division.
  • The program expects the user to input the numbers separated by a comma (e.g., 12.5, 8).
  • No advanced error checking is implemented beyond the basic checks for invalid operators and division by zero.

Future Enhancements

  • Implement additional operations like modulus (%) or exponentiation.
  • Improve user input handling (e.g., accept space-separated inputs for numbers).
  • Add support for more advanced mathematical functions (e.g., square roots, trigonometric functions).

Let me know if you need further modifications or additional information!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages