# Calculator code

**URL:** <https://discourse.processing.org/t/calculator-code/35540>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [March 3, 2022, 3:41pm UTC](https://discourse.processing.org/t/calculator-code/35540 "2022-03-03T15:41:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![suarezl](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@suarezl](https://discourse.processing.org/u/suarezl)\
**Post date:** [March 3, 2022, 3:41pm UTC](https://discourse.processing.org/t/calculator-code/35540/1 "2022-03-03T15:41:09Z")

</div>

Hello, I am starting in this world, I need help with the code of a calculator, the truth is that I still do not have the necessary knowledge to be able to carry it out, I wanted to see if someone could help me, thanks and regards

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2022, 4:33pm UTC](https://discourse.processing.org/t/calculator-code/35540/2 "2022-03-03T16:33:00Z")

</div>

Do you want to use it via keyboard or with mouse?

Do you plan to have a graphic of the buttons of the calculator?

You can find more here: [Reference / Processing.org](https://processing.org/reference)

And examples: [Examples / Processing.org](https://processing.org/examples)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 3, 2022, 5:23pm UTC](https://discourse.processing.org/t/calculator-code/35540/3 "2022-03-03T17:23:42Z")

</div>

What code do you have so far? Do you have setup() and draw() functions?

Can you draw buttons using fill(), stroke(), rect(), and text()?

Do you have a mousePressed() function? Does it check the mouse’s position for things?

We really need to see some code to be able to help you. Please attempt some, and post your attempt.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 4, 2022, 12:31am UTC](https://discourse.processing.org/t/calculator-code/35540/4 "2022-03-04T00:31:06Z")

</div>

You need

- a “display” rect() with the number
- the buttons (1,2,… + , -, =… )
- and a concept: what’s happening

**what’s happening:**

- you type number (number 1), display it, add new input at the end of number (meaning when you have 4 and type 3, you get 43)
- You type +,- etc…: Number is hidden, but you store the number and the function (+ or - or / …)
- You type, the 2nd number gets displayed…
- and so forth…
