Skip to content
← Back to Community
An actual good calculator
Profile icon
FlaminHotValdez

There are like a BAJILLION posts on replit that are "calculators" that go like this:

Please input which operation you would like: Plus, minus, add, or divide

Please input which numbers you would like to add.

I got bored of those, and I made a calculator where you can just straight up input the expression you want to calculate. Works with +,-,*,/,^ for exponent, and parentheses! Not only that it follows order of operations too. It even has decimal capability of 10 places. Also, no eval() function.

The purpose of this post? To make a calculator where you can just enter your math expression instead of printing "Plus, minus, multiply or divide?" without using eval. also to prove that stacks are useful because basically no posts on replit use stacks

EDIT: Y'all are razzing on me because my calculator doesn't work for super big numbers or if you just input gibberish. But seriously there is a thing called integer limit... sigh

UPDATE: Floor division has been added.

Voters
Profile icon
AnaghRaina
Profile icon
hydynn
Profile icon
SelenaYang1
Profile icon
XanthusPettitt
Profile icon
GhostKing007
Profile icon
Baconman321
Profile icon
Whippingdot
Profile icon
forceofyoda
Profile icon
Brendan23
Profile icon
tussiez
Comments
hotnewtop
Profile icon
SilvermoonCat

185D07C5-1CF4-4075-9135-9BEBAF8B8A10
hmph, for one other test it returned “inf”

Profile icon
FlaminHotValdez

@SilvermoonCat Do you not know of a thing called integer limit?

Profile icon
SilvermoonCat

@FlaminHotValdez ofc I do I was just trying some "things'

Profile icon
Coder100
Profile icon
FlaminHotValdez

@Coder100 It doesn't work with equations, only + - * / ^ ()

Profile icon
angrydoge
Profile icon
tussiez
Profile icon
FlaminHotValdez

@tussiez sigh, yall are razzing on me for having "bad math" but no other calculator on replit can handle big numbers, equations, and random letters. At least my calculator allows you to straight up enter an expression and it follows pemdas instead of other basic calculators that can literally do one operation.

Profile icon
tussiez
Profile icon
FlaminHotValdez

@tussiez html eval? Sigh. Seriously the whole point of this post was to not use eval and have a straight-up expression input instead of "Would you like to add, subtract, multiply or divide?"

Profile icon
tussiez

@FlaminHotValdez HTML JS
Yee, that's what I like about this post, and why it has my upvote

Profile icon
FlaminHotValdez

@tussiez ...Yes js eval much better lol...Glad u like it tho, but yeah the whole point of this post is to have a calculator where you can just enter your expression instead of printing "Plus, minus, multiply or divide?" without eval and similar functions.

Profile icon
tussiez
Profile icon
Coder100

wait looking at your code it's more of a regular lang than a context-free lang. what's going on here @FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100 ? Wdym?

Profile icon
Coder100

it doesn't fully recurse @FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100 it's...not a recursion-based thing, it's a stack

Profile icon
Coder100

for example, you don't really care if the equation is valid, and thus you can easily have it segfault @FlaminHotValdez

Profile icon
Coder100

the thing is a context-free language, which math is, recurses so to have precedence @FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100 yeah IK lol, but I wasn't trying to make it perfect, the goal of this was just to make a calculator where you could just enter the expression instead of choosing what operation then entering the integers. Also no eval.

Profile icon
FlaminHotValdez

@Coder100 I do have precedence, the code is super complicated but trust me it works

Profile icon
jihhyuu202

you can use strings to store the number [email protected]

Profile icon
FlaminHotValdez

@jihhyuu202 wdym? I am using a string but my method of calculation relies on stack

Profile icon
Coder100

strings won't work because you can't do calculations with them @FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100 ik that's what I said: my method of calculation depends on stack

and what are you doing here?

Profile icon
Coder100

i got the ping @FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100 oh

so you respond to pings?

Profile icon
henryeth

Me: makes good calculator.
After that.
Valdez: makes similarly good calculator.
Me: gets 3 upvotes.
Valdez: gets 15+ upvotes and a ton of recognition.
How I love repl.it.

Profile icon
FlaminHotValdez

@henryeth Not my fault! cowers behind wall

Profile icon
FlaminHotValdez

@henryeth also if you haven't noticed everybody's shaming on my calculator lol

Profile icon
henryeth

@FlaminHotValdez yh I am sure it would be the same for me tbh. I know it isn't your fault. It is in a different language (maybe that is the reason???) so it obviously isn't any kind of a copy (the one thing I would be especially angry if it was).

Profile icon
FlaminHotValdez

@henryeth lol...no offense but this repl was created and coded about 10 months ago, recently I added a bit and debugged it you can look at the history.

Profile icon
henryeth

@FlaminHotValdez really wow, no offense taken

Profile icon
henryeth

@FlaminHotValdez haha yes now I have winning calculator again :evil laugh: check my new post.

Profile icon
FlaminHotValdez

@henryeth ah rip

Profile icon
MaxFromYT

9^-98765 dumped it

Profile icon
DaCuteRaccoon

image

LOL I just caused a core dump by declaring a variable x = 2 (without the type specification like int, long long int, float, etc.) and then return x to the power of x (2**2). You should really add algebraic expressions :)

Profile icon
FlaminHotValdez

@DaCuteRaccoon easier said than done

Profile icon
DaCuteRaccoon

You can use things like long long int. Or you could not use cpp to make it.

Profile icon
FlaminHotValdez

@DaCuteRaccoon Yeah, but that's memory murder

Profile icon
DynamicSquid

Hi, this is really random but do you do competitive programming? I think I saw it in a comment somewhere

Profile icon
FlaminHotValdez

@DynamicSquid Yeah! I do! In fact, this post was actually originally one of the problems I did for practice

Profile icon
DynamicSquid

@FlaminHotValdez Nice! I do too (although not good at it) Which website do you use?

Profile icon
FlaminHotValdez

@DynamicSquid I participate in the USACO contests(And I'm terrible. Welcome to the club). I'm enrolled in a coding class, and they also have a website full of coding problems. Also I think we had this "competitive programming" thread somewhere else...I lost it though lol

Profile icon
DynamicSquid

@FlaminHotValdez Cool! Planning to join the USA coding olympiad?

Profile icon
FlaminHotValdez

@DynamicSquid Already participating

And failing hard

Yippee!

WBU? I think you're in Canada or something?

Profile icon
DynamicSquid

@FlaminHotValdez Yeah, I'm in Canada. First we have the Canadian Computing Competition (CCC). Each year there's about 7000 participants. If you get around top 20, then you're invited to the Canadian Computing Olympiad (CCO). The top 4 from the CCO go to the International Olympiad of Informatics (IOI) 👀.

Last year I was like bottom 6000 in Canada lol. But this year I was top 731. And next year, which will be my last year, I'm really hoping to be top 20 to get into the CCO 🙏

Profile icon
FlaminHotValdez

@DynamicSquid Cool! In the USA, we have the USACO(United States of America Computing Olympiad), which is split into 4 tiers. Bronze, silver, gold, and platinum. You start out at bronze. When you take the contest, you take the contest respective to your tier, and if you do well(Usually 75%), you advance to the next tier. The USACO contests are held four times a year. Once in December, once in January, and once in February. Then there's the one called the "US Open." It usually takes place in March, but this year it happened in early April. The questions on the US Open are harder than the other contests, and the top 20-ish scorers from Platinum in the US Open advance to a "camp" of sorts. Then, the top 4 in the "camp" are chosen to go to the IOI. Last year in February, I advanced from bronze to silver. And I've been stuck on the silver for 5 contests straight. They say it's the biggest jump between levels.

EDIT: If you read through that entire paragraph I apologize on behalf of your eyes.

Profile icon
DynamicSquid

@FlaminHotValdez Interesting! I think America has won 3 consecutive gold medals at the IOI so far, so you guys are doing way better than us! Well, good luck for the December contest :)

Profile icon
FlaminHotValdez

@DynamicSquid

Thanks! Good luck to you too! And yeah...USA has won 3 consecutive gold medals in the past 3 years. But I think the tides will turn...

benjamin qi is gone from the team mwahahahahahahahah

sadly he still writes problems
Profile icon
Whippingdot

I live in India, so is there any way I can try qualifying in the IOI? The only website I found looked very ummm bad. The IOI website didn't help me as it didn't talk about the countries that participate @FlaminHotValdez

Profile icon
Whippingdot

Also, I have to live in USA to do that USACO thing right? I can't do it even though I was born there? @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot No, USACO is open for everyone, but only US citizens that are not yet college age can qualify for IOI. I'm not sure whether India is in ioi tho :(

Profile icon
XanthusPettitt

how does python stacks work?

Profile icon
FlaminHotValdez

@XanthusPettitt I'm actually not sure if Python has an innate stack.

Profile icon
XanthusPettitt

@FlaminHotValdez oh... well then ok lol

Profile icon
XanthusPettitt

hey, @flamingHotValdez, I'm making a calc of my own could you take a look at it? its not finished but I feel like it could use some tuning

Profile icon
Kudos

I'm not insulting your calculator I'm just meme-ing chill

image

image

If x = 72 then 2x = 92 😁 I luv math

Profile icon
FlaminHotValdez

@Kudos ascii, the ascii for x = 72

Profile icon
btfuss

stop the program and type into the bash:
cpp main.cpp

Profile icon
code-alt
Profile icon
FlaminHotValdez

@codealt1 no spaces, also 5/0 will throw error.

Profile icon
code-alt

@FlaminHotValdez you have made a fine calculator

image

Profile icon
FlaminHotValdez

@codealt1 I was too lazy to throw an exception. The point of this was not to make a perfect calculator but rather one that has more capacity than [number][operator][number] without using eval() or similar functions.

Profile icon
Baconman321

I really need to do a calculator via the shunting yard algorithm....
Sigh...

Profile icon
StrangeQuarkAL

You just made a parser(not a very good one tbh) and an evaluator.

IT'S STILL COOL THO!!!

Profile icon
FlaminHotValdez

@StrangeQuarkAL The point of this was to make a calculator that could actually parse expressions and evaluate them correctly without using eval() function and similar. So yeah. The vast majority of calculators on repl.it neither parse nor evaluate without using the eval() function so I consider this an accomplishment.

Profile icon
StrangeQuarkAL

@FlaminHotValdez Yeah, I get it, like I said, "it's still cool tho!!!".
Anyway, I'm gonna make one too. Seems simple enough and I'm extremely bored

Profile icon
FlaminHotValdez

@StrangeQuarkAL xD boredom drives me to do most of my coding projects

Profile icon
StrangeQuarkAL
Profile icon
darkdarcool
Profile icon
FlaminHotValdez

@darkdarcool no spaces

Profile icon
darkdarcool
Profile icon
INCOGNITO001

lol might've said this already but... Finally a decent C++ project on repl.it!

Profile icon
FlaminHotValdez

@gjirtngisnt thanks <3

Profile icon
LTI2
Profile icon
FlaminHotValdez

@LTI2 DO YOU NOT KNOW OF A THING CALLED INTEGER LIMIT. IF YOU INPUT THAT IN ANY LANGUAGE IT WOULDN'T WORK.

Profile icon
LTI2

@FlaminHotValdez i know, i also inputed letters and random stuff but how did it come up with this answer

Profile icon
FlaminHotValdez

@LTI2 u overloaded it with crazy inputs so it gives you a crazy answer.

Profile icon
glitchish

@FlaminHotValdez instead of as the input make it visual like Type some math: or something

Profile icon
FlaminHotValdez

@CodingRedpanda Ye lmao I'm trash

Profile icon
glitchish

@FlaminHotValdez
image
much better

** xD **

Profile icon
glitchish
Profile icon
FlaminHotValdez

@CodingRedpanda BRUH JUST QUIT MESSING IT UP AND PUT IN LEGIT MATH EXPRESSIONS.

Profile icon
glitchish

@FlaminHotValdez OK I WILL PUT IN 0 ÷ 0 AND SEE WHAT HAPPENS (since that is legit in itself)

Profile icon
angrydoge

I already did that @CodingRedpanda
its -NaN

Profile icon
FlaminHotValdez

@CodingRedpanda Are you TRYING to make my calculator go crazy?

Profile icon
glitchish
Profile icon
IntellectualGuy
Profile icon
glitchish

@FlaminHotValdez

There are like a BAJILLION posts on replit that are "calculators" that go like this:
Please input which operation you would like: Plus, minus, add, or divide
Please input which numbers you would like to add.

so true! no offence anyone
but here is my calculator: My Actual Calculator

Profile icon
FlaminHotValdez

@CodingRedpanda No exponent? C'mon!

Profile icon
IntellectualGuy

This is

Pog

and I've remade it in python here

Profile icon
angrydoge

I had made one similar to this cpp one lol @IntellectualGuy

Profile icon
Whippingdot

First of all pretier would murder you for this code. Second of all does this work??????

image

Profile icon
FlaminHotValdez

@Whippingdot yes and it's bad code quality but I'm lazy

Profile icon
angrydoge

Screenshot 2021-01-29 at 8.32.17 AM

lol -NaN? How does negative not a number work?

Also before the cookie says it

POG

Profile icon
FlaminHotValdez
Profile icon
FlaminHotValdez

@angrydoge ask c++ lol, this is a basic calculator and the thing diffrentiating it from other calculator posts is that you can just straight up input the expression and it follows pemdas.

Profile icon
angrydoge

too bad i ruin ALL calculators @FlaminHotValdez

hehehehe >:)
Profile icon
ElixirAlpha

these c++ programs NEVER work for me idk why

Profile icon
FlaminHotValdez

@PilotDevKarwa Bruh run and then input the statement. There's no fancy print statements for politeness.

Profile icon
ElixirAlpha

I AM RUNNING IT IT DOESN"T WORK it just stops after ./main @FlaminHotValdez

Profile icon
FlaminHotValdez

@PilotDevKarwa it doesn't output anything you have to input ur statement

Profile icon
FlaminHotValdez

then it outputs

Profile icon
Whippingdot

Actually, why do you have to make this. I AM RAGED, I AM DOING THIS TOO. WHYYYYYY. I AM DOING THE SAME THING RIGHT NOW!!!! YOU WASTED MY PROGRAM. UGGGGGGG

Profile icon
FlaminHotValdez

@Whippingdot well..umm...hides

Profile icon
Whippingdot

Well I was making a calculator just for fun anyway. I was not planning to share it until recently. I won't share it. But I AM STILL THE ONE TO MAKE THE TUTORIALS. I MADE THE FIRST TUTORIAL ALREADY AND YOU ARE NOT ALLOWED TO MAKE A TUTORIAL ON THIS!!! I BAN YOU!!! but actually bruh i am making tutorials on how to make calculators in C++ so please let me do that at least(I made my first one already check it out in the new area of tutorials) @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot Oh lol, sorry, I didn't know u were making tutos this is an old repl, if you check the history I made it like 10 months ago but I got pissed off at all the calculators that are messes of if statements so I posted this.

Profile icon
Whippingdot

lul JUST CHECK OUT MY TUT @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot

no

well I did
Profile icon
ElixirAlpha

chill max and whipping dot. you can make anoterh [email protected]

Profile icon
Whippingdot

Wait a sec, how did you know he is maxyang? Who are you, did you forget to switch your account? Also me and flaminhotvaldex(max) are friends @PilotDevKarwa

Profile icon
FlaminHotValdez

@Whippingdot nah he's my classmate.

Profile icon
ElixirAlpha

hes in my class duhhhh hes also my [email protected]

Profile icon
Whippingdot

Bruh you have to put a space before @ mentioning or else it doesn't work @PilotDevKarwa

Profile icon
Whippingdot

Lol i only remember because of the ahem i am talking about you ahem thing @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot LOLOLOLOL also @PilotDevKarwa is new to replit he mostly uses it for skool

Profile icon
Whippingdot

uuuu kay I hope we stay friends @FlaminHotValdez. You and @JBYT27 are the only ones who pay attention to me

Profile icon
FlaminHotValdez

@Whippingdot rly? OOF. it's fine we're cool :) no one rly pays attention to us 200-cyclers

Profile icon
Whippingdot

yup let us become 300 cyclers @FlaminHotValdez

Profile icon
JBloves27
Profile icon
JBloves27

Lol, what about me? Lol @FlaminHotValdez

Profile icon
Whippingdot

Except you @JBYT27. You are an exception. Even @angrydoge is one

Profile icon
angrydoge

Im a what? @Whippingdot

HMMMMMMMMMMMM
Profile icon
Whippingdot

Exeption. You guys pay attention to us 200 cyclers. @angrydoge

Profile icon
angrydoge

Well duh. Why tf would cycles matter @Whippingdot.
I mean I used to be a 3 cycles dude who posted crud projects. 200 cycles is a lot.
I dont care about cycles for respect, if youre a trusted member (u are :D) of Replit or I trust you I pay attention.

If you think cycles = respect, thats wrong. tbh it makes people farm cycles.

Profile icon
angrydoge

Well I know youre {name} so maybe delete those comments @FlaminHotValdez

Profile icon
Whippingdot

lol true you have to delete them @FlaminHotValez. Also most people on repl.it aren't like that @angrydoge. They don't care about us. Me, you, JB, and maxyang all have conversations at least.

Profile icon
JBloves27

lmao, ok xd @Whippingdot

Profile icon
JBloves27

lol, yeah @Whippingdot

Profile icon
Whippingdot

@JBYT27 & @angrydoge i think maxyang died

Profile icon
JBloves27
Profile icon
FlaminHotValdez

@angrydoge oh crap I have to delete those comments

Profile icon
FlaminHotValdez

@Whippingdot I was sleping I'm pacific time

Profile icon
angrydoge

yeah dont give out your name on Repl.it @FlaminHotValdez

Profile icon
angrydoge

ye like get nae naed @Whippingdot

Profile icon
JBloves27
Profile icon
Whippingdot

I am in ist time... @FlaminHotValdez

Profile icon
Whippingdot

STOOOP IT GET WHIPPED PLEASE @angrydoge

Profile icon
FlaminHotValdez

@angrydoge xD there are lots of people who actually state their name on their profile and a few that even have their name in their username.

Profile icon
INCOGNITO001

@angrydoge how do u get cycles anyways

Profile icon
angrydoge

um what @gjirtngisnt
cycles = upvotes
If i upvote a comment/post, OP gets 1 more cycle.

Profile icon
angrydoge
Profile icon
JBloves27

Hahahahaha, luv the frog xd @angrydoge

Profile icon
angrydoge

froge lol @JBYT27

Profile icon
JBloves27

Yees froge @angrydoge

Profile icon
FlaminHotValdez

@JBYT27 froge

Profile icon
angrydoge

@JBYT27

froge
froge :>>

doge + frog XDD
Profile icon
FlaminHotValdez

@angrydoge that actually looks like a froge though...

Profile icon
angrydoge

it is a froge doge + frog. @FlaminHotValdez

Profile icon
Whippingdot

why don't you become frogdoge @angrydoge

Profile icon
JBloves27
Profile icon
JBloves27
Profile icon
Whippingdot
Profile icon
angrydoge
Profile icon
angrydoge

Brej @JBYT2Also look at vandesm being a madlad
download_20210129_202609

Profile icon
Whippingdot

Wait a sec looooool which post is that on send it to me @angrydoge

Profile icon
Whippingdot

What did vandesm only get one cycle since then? Your's says 3 hrs but mine says 6 months. 😲😲😲 https://repl.it/talk/share/Questions/49897 @angrydoge

Profile icon
angrydoge

Idk what post but it was new @Whippingdot

Profile icon
Whippingdot

Not at all new, it was 6 months ago 🤦‍♂️🤦‍♂️🤦‍♂️ @angrydoge

Profile icon
angrydoge

Oh my gosh @Whippingdot I never said THAT post the one I took a screenshot of is new 🤦‍♂️

Profile icon
Whippingdot

But it was the same words... @angrydoge

Profile icon
angrydoge
Profile icon
FlaminHotValdez

@angrydoge @Whippingdot Me in getting 16 notifs overnight:

Screenshot from 2021-01-19 19-58-52

^Now I know that's true.^

Profile icon
angrydoge
Profile icon
FlaminHotValdez

@angrydoge Time to steal @RhinoRunner 's meme.
What's it called when you actually get notifications on repl.it?

imagination

Profile icon
Whippingdot
Profile icon
FlaminHotValdez

@Whippingdot WELP guess what you're at 298 and I'm at 295.
cmon let us become 300 cyclersssss

Profile icon
Whippingdot

HOW DID I CATCH UP TO YOU WOOOO bRuH hOw dId I cAtCh uP tO yOu???? @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot ur 2021 post. now let us upvote each other's comments in this thread and get to 300 cycles

Profile icon
Whippingdot

Lul. U know you weren't supposed to answer that question. Also this is cheating but...welp @FlaminHotValdez

Profile icon
FlaminHotValdez
Profile icon
Whippingdot

HEY! you got 301, cheater @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot o.o someone must've upvoted one of my comments...

Profile icon
Whippingdot

CHEEAAAAAAATERRRRR @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot alright, memefest time 400 for you woooo

Profile icon
Whippingdot

yaaaaay you only 350 get rekt Ima start making my own good programs and posting them. Usually I get updoots from comments but I want that to change... @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot Same here this is my only medium ish post

Profile icon
FlaminHotValdez

@Whippingdot you casually reaching 500 before I reach 400

Profile icon
Whippingdot

lul i have 113 more cycles than you POG @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot 600 for both of us

*dances*

Profile icon
Whippingdot

bruh you hacking how did you cross me? AAAAAAAAAAAAAAA HACKER @FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot cactus looked into it, one of my friends mass upvoted me

Profile icon
noway15

You know, C++ in Javascript would actually be C+1 come to think of it

Profile icon
Coder100

it would be cooler if you also printed an AST
also wtf

image

there's a reason || exists... you know

Profile icon
FlaminHotValdez

@Coder100 Shun that. Text shall rule forever.

Profile icon
Whippingdot

wait you can write or? I didn't know that works @FlaminHotValdez

Profile icon
INCOGNITO001

@FlaminHotValdez TEXT FOREVER

Profile icon
henryeth

I do python and H, C, J. I have no idea how C++ works and for some reason I can’t get to is to load. But judging by the code, this is good. And I mean good. Like I made a pretty good calculator with H, C, J recently (shameless self promotion: go check that out) and that one was far far better than the tiny spammed console ones. But order of operations must add a whole knew layer of complexity. I applaud this.

Profile icon
FlaminHotValdez

@henryeth Actually once it prints ./main.cpp you can type in your expression, it doesn't actually print "Please input your expression or stuff like that." Thanks though!

Profile icon
henryeth

Oh right ok thanks @FlaminHotValdez