Share your repls and programming experiences

← Back to all posts
An actual good calculator
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
hydynn
SelenaYang1
XanthusPettitt
GhostKing007
Baconman321
Whippingdot
forceofyoda
Brendan23
tussiez
KobeFF
Comments
hotnewtop
SilvermoonCat


hmph, for one other test it returned “inf”

FlaminHotValdez

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

SilvermoonCat

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

Coder100


ah, yes, math

FlaminHotValdez

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

angrydoge
tussiez
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.

tussiez
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?"

tussiez

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

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.

tussiez
Coder100

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

FlaminHotValdez

@Coder100 ? Wdym?

Coder100

it doesn't fully recurse @FlaminHotValdez

FlaminHotValdez

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

Coder100

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

Coder100

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

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.

FlaminHotValdez

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

jihhyuu202

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

FlaminHotValdez

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

Coder100

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

FlaminHotValdez

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

and what are you doing here?

Coder100

i got the ping @FlaminHotValdez

FlaminHotValdez

@Coder100 oh

so you respond to pings?

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.

FlaminHotValdez

@henryeth Not my fault! cowers behind wall

FlaminHotValdez

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

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).

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.

henryeth

@FlaminHotValdez really wow, no offense taken

henryeth

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

FlaminHotValdez

@henryeth ah rip

DynamicSquid

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

FlaminHotValdez

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

DynamicSquid

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

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

DynamicSquid

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

FlaminHotValdez

@DynamicSquid Already participating

And failing hard

Yippee!

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

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 🙏

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.

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 :)

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
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

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

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 :(

XanthusPettitt

how does python stacks work?

FlaminHotValdez

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

XanthusPettitt

@FlaminHotValdez oh... well then ok lol

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

Kudos

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

If x = 72 then 2x = 92 :grin: I luv math

FlaminHotValdez

@Kudos ascii, the ascii for x = 72

btfuss

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

codealt1

huh.

huh.

FlaminHotValdez

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

codealt1

@FlaminHotValdez you have made a fine calculator

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][number] without using eval() or similar functions.

Baconman321

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

StrangeQuarkAL

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

IT'S STILL COOL THO!!!

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.

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

FlaminHotValdez

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

StrangeQuarkAL
darkdarcool

Math is amazing:

FlaminHotValdez

@darkdarcool no spaces

darkdarcool
INCOGNITO001

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

FlaminHotValdez

@gjirtngisnt thanks <3

LTI2

Wow this is amazing math

@FlaminHotValdez

FlaminHotValdez

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

LTI2

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

FlaminHotValdez

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

iocoder

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

FlaminHotValdez

@CodingRedpanda Ye lmao I'm trash

iocoder

@FlaminHotValdez

much better

xD

iocoder

@CodingRedpanda

yep, thats math

FlaminHotValdez

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

iocoder

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

angrydoge

I already did that @CodingRedpanda
its -NaN

FlaminHotValdez

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

iocoder
IntellectualGuy
iocoder

@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

FlaminHotValdez

@CodingRedpanda No exponent? C'mon!

IntellectualGuy

This is

Pog

and I've remade it in python here

angrydoge

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

Whippingdot

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

FlaminHotValdez

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

angrydoge

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

Also before the cookie says it

POG

FlaminHotValdez
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.

angrydoge

too bad i ruin ALL calculators @FlaminHotValdez

hehehehe >:)
ElixirAlpha

these c++ programs NEVER work for me idk why

FlaminHotValdez

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

ElixirAlpha

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

FlaminHotValdez

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

FlaminHotValdez

then it outputs

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

FlaminHotValdez

@Whippingdot well..umm...hides

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

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.

Whippingdot

lul JUST CHECK OUT MY TUT @FlaminHotValdez

FlaminHotValdez

@Whippingdot

no

well I did
ElixirAlpha

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

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

FlaminHotValdez

@Whippingdot nah he's my classmate.

ElixirAlpha

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

Whippingdot

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

Whippingdot

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

FlaminHotValdez

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

Whippingdot

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

FlaminHotValdez

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

Whippingdot

yup let us become 300 cyclers @FlaminHotValdez

JBloves27

Lol, oof @Whippingdot

JBloves27

Lol, what about me? Lol @FlaminHotValdez

Whippingdot

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

angrydoge

Im a what? @Whippingdot

HMMMMMMMMMMMM
Whippingdot

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

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.

angrydoge

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

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.

JBloves27

lmao, ok xd @Whippingdot

JBloves27

lol, yeah @Whippingdot

Whippingdot

@JBYT27 & @angrydoge i think maxyang died

JBloves27

oh noes @Whippingdot

FlaminHotValdez

@angrydoge oh crap I have to delete those comments

FlaminHotValdez

@Whippingdot I was sleping I'm pacific time

angrydoge

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

angrydoge

ye like get nae naed @Whippingdot

JBloves27
Whippingdot

I am in ist time... @FlaminHotValdez

Whippingdot

STOOOP IT GET WHIPPED PLEASE @angrydoge

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.

INCOGNITO001

@angrydoge how do u get cycles anyways

angrydoge

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

angrydoge
JBloves27

Hahahahaha, luv the frog xd @angrydoge

angrydoge

froge lol @JBYT27

JBloves27

Yees froge @angrydoge

FlaminHotValdez

@JBYT27 froge

angrydoge

@JBYT27


froge :>>

doge + frog XDD
FlaminHotValdez

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

angrydoge

it is a froge doge + frog. @FlaminHotValdez

Whippingdot

why don't you become frogdoge @angrydoge

JBloves27
JBloves27

XDDDDD @angrydoge

Whippingdot

My second meme @angrydoge

angrydoge

Ew wtf @Whippingdot

angrydoge

Brej @JBYT2Also look at vandesm being a madlad

Whippingdot

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

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

angrydoge

Idk what post but it was new @Whippingdot

Whippingdot

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

angrydoge

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

Whippingdot

But it was the same words... @angrydoge

angrydoge

Nae nae @Whippingdot

FlaminHotValdez

@angrydoge @Whippingdot Me in getting 16 notifs overnight:

^Now I know that's true.^

angrydoge
FlaminHotValdez

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

Whippingdot
FlaminHotValdez

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

Whippingdot

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

FlaminHotValdez

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

Whippingdot

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

FlaminHotValdez
Whippingdot

HEY! you got 301, cheater @FlaminHotValdez

FlaminHotValdez

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

Whippingdot

CHEEAAAAAAATERRRRR @FlaminHotValdez

FlaminHotValdez

@Whippingdot alright, memefest time 400 for you woooo

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

FlaminHotValdez

@Whippingdot Same here this is my only medium ish post

FlaminHotValdez

@Whippingdot you casually reaching 500 before I reach 400

Whippingdot

lul i have 113 more cycles than you POG @FlaminHotValdez

FlaminHotValdez

@Whippingdot 600 for both of us

*dances*

Whippingdot

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

FlaminHotValdez

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

noway15

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

Coder100

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

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

FlaminHotValdez

@Coder100 Shun that. Text shall rule forever.

Whippingdot

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

INCOGNITO001

@FlaminHotValdez TEXT FOREVER

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.

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!

henryeth

Oh right ok thanks @FlaminHotValdez