Skip to content

tyboyd02/go-cli-calc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calculator Program

This calculator program evaluates mathematical expressions by following the PEMDAS order of operations. It utilizes the Shunting Yard algorithm to convert Infix notation 4.2+18/(9-3) to Reverse Polish notation 4.2 18 9 3 - / + before solving.

Supported Symbols

  • Parentheses: (, )
  • Operators:
    • ^ (exponentiation)
    • * (multiplication)
    • / (division)
    • + (addition)
    • - (subtraction)

Usage Examples

go-cli-calc 2+2*2
	OUTPUT: 6
	
go-cli-calc "4.2 + 18 / (9 - 3)"
	OUTPUT: 7.2

go-cli-calc "(1-.5)+2*9+2"
	OUTPUT: 20.5

NOTES

  • Whitespace between numbers and operators will not affect the calculation
  • You may be able to omit the quotes "" if there is no white space between the numbers and operators

Known issues

  • Can't do -(2+2)

About

CLI Calculator written in Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages