Skip to content

suzshiro1024/calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

Calculator

A simple calculator using stack.

How to use?

  1. Compile each file individually.
gcc stack.c -c
gcc parse.c -c
gcc calc.c -c
gcc main.c -c
  1. Link all executable files.
gcc -o ${hoge} stack.o parse.o calc.o main.o
  1. Prepare a file "calc.txt" with the calculation formula. -> You can skip this step.

For example, the contents of calc.txt should be as follows.

100+100
  1. Run the executable file created in (2.)

When you open calc.txt, the contents should change as follows!

100+100=200

Specifications

Operators you can use

You can use the five operators '+', '-', '*', '/', '()'.

+

The operator + adds the two numbers to the left and right of itself.

However, if the operator *,/ takes either the left or right number as its argument, it will take precedence.

-

The operator - subtracts the two numbers to the left and right of itself.

However, if the operator *,/ takes either the left or right number as its argument, it will take precedence.

  • Caution

    If you want to use a negative number, be sure to subtract it from other numbers.

    Don't put the number with a minus sign by itself.

    • Example

      Bad : -2200+2000
      Good: 2000-2200
      
      Bad : -2000
      Good: 0-2000
      

*

The operator * times the two numbers to the left and right of itself.

/

The operator / divides the two numbers to the left and right of itself.

  • Caution This calculator only supports integers, so if the result of division is not an integer, truncation will occur.

    • Example

      10/2 = 5
      10/3 = 3
      2/3 = 0
      

()

The operator() makes the computation in it take precedence over all other computations.

This is not related to the rule that '*,/' takes precedence over '+,-'.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages