Share your repls and programming experiences

← Back to all posts
An actual good calculator
FlaminHotValdez (690)

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.

Comments
hotnewtop
SilvermoonCat (435)


hmph, for one other test it returned “inf”

FlaminHotValdez (690)

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

SilvermoonCat (435)

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

FlaminHotValdez (690)

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

FlaminHotValdez (690)

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

FlaminHotValdez (690)

@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 (1666)

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

FlaminHotValdez (690)

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

Coder100 (18146)

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

FlaminHotValdez (690)

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

Coder100 (18146)

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

Coder100 (18146)

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

FlaminHotValdez (690)

@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 (690)

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

henryeth (184)

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 (690)

@henryeth Not my fault! cowers behind wall

FlaminHotValdez (690)

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

henryeth (184)

@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 (690)

@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 (184)

@FlaminHotValdez really wow, no offense taken

henryeth (184)

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

DynamicSquid (4916)

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

FlaminHotValdez (690)

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

DynamicSquid (4916)

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

FlaminHotValdez (690)

@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 (4916)

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

FlaminHotValdez (690)

@DynamicSquid Already participating

And failing hard

Yippee!

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

DynamicSquid (4916)

@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 (690)

@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 (4916)

@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 (690)

@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 (657)

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 (657)

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 (690)

@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 (10)

how does python stacks work?

FlaminHotValdez (690)

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

XanthusPettitt (10)

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 (138)

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

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

FlaminHotValdez (690)

@Kudos ascii, the ascii for x = 72

btfuss (177)

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

FlaminHotValdez (690)

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

codealt1 (3)

@FlaminHotValdez you have made a fine calculator

FlaminHotValdez (690)

@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 (1097)

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

StrangeQuarkAL (0)

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

IT'S STILL COOL THO!!!

FlaminHotValdez (690)

@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 (0)

@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 (690)

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

INCOGNITO001 (15)

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

FlaminHotValdez (690)

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

LTI2 (116)

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

FlaminHotValdez (690)

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

iocoder (162)

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

FlaminHotValdez (690)

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

iocoder (162)

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

FlaminHotValdez (690)

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

iocoder (162)

@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

IntellectualGuy (823)

This is

Pog

and I've remade it in python here

angrydoge (481)

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

Whippingdot (657)

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

FlaminHotValdez (690)

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

angrydoge (481)

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

Also before the cookie says it

POG

FlaminHotValdez (690)

@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 (481)

too bad i ruin ALL calculators @FlaminHotValdez

hehehehe >:)
ElixirAlpha (12)

these c++ programs NEVER work for me idk why

FlaminHotValdez (690)

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

ElixirAlpha (12)

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

FlaminHotValdez (690)

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

Whippingdot (657)

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

Whippingdot (657)

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 (690)

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

ElixirAlpha (12)

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

Whippingdot (657)

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

ElixirAlpha (12)

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

Whippingdot (657)

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

Whippingdot (657)

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

FlaminHotValdez (690)

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

Whippingdot (657)

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

FlaminHotValdez (690)

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

Whippingdot (657)

yup let us become 300 cyclers @FlaminHotValdez

Whippingdot (657)

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

Whippingdot (657)

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

angrydoge (481)

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 (481)

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

Whippingdot (657)

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.

FlaminHotValdez (690)

@angrydoge oh crap I have to delete those comments

FlaminHotValdez (690)

@Whippingdot I was sleping I'm pacific time

angrydoge (481)

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

Whippingdot (657)

STOOOP IT GET WHIPPED PLEASE @angrydoge

FlaminHotValdez (690)

@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 (15)

@angrydoge how do u get cycles anyways

angrydoge (481)

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

JBloves27 (1884)

Hahahahaha, luv the frog xd @angrydoge

angrydoge (481)

@JBYT27


froge :>>

doge + frog XDD
FlaminHotValdez (690)

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

Whippingdot (657)

why don't you become frogdoge @angrydoge

angrydoge (481)

Brej @JBYT2Also look at vandesm being a madlad

Whippingdot (657)

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

Whippingdot (657)

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 (481)

Idk what post but it was new @Whippingdot

Whippingdot (657)

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

angrydoge (481)

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

Whippingdot (657)

But it was the same words... @angrydoge

FlaminHotValdez (690)

@angrydoge @Whippingdot Me in getting 16 notifs overnight:

^Now I know that's true.^

FlaminHotValdez (690)

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

FlaminHotValdez (690)

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

Whippingdot (657)

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

FlaminHotValdez (690)

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

Whippingdot (657)

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

FlaminHotValdez (690)

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

FlaminHotValdez (690)

@Whippingdot alright, memefest time 400 for you woooo

Whippingdot (657)

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 (690)

@Whippingdot Same here this is my only medium ish post

FlaminHotValdez (690)

@Whippingdot you casually reaching 500 before I reach 400

Whippingdot (657)

lul i have 113 more cycles than you POG @FlaminHotValdez

Whippingdot (657)

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

FlaminHotValdez (690)

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

noway15 (97)

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

Coder100 (18146)

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

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

FlaminHotValdez (690)

@Coder100 Shun that. Text shall rule forever.

Whippingdot (657)

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

henryeth (184)

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 (690)

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