# Basic calculator code error: "it looks like you are mixing active and static modes"

**URL:** https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194
**Category:** Coding Questions
**Created:** [January 4, 2019, 10:00pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194 "2019-01-04T22:00:59Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 10:00pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/1 "2019-01-04T22:00:59Z")

</div>

I have a error it looks like you are mixing active and static modes can you help me

My code:

```auto
String input = "";

float input1 = 0;
float input2 = 0;
float result = 0;

int operator = 0;

boolean drawResult = false;

void setup() {

  background(255);
  size(720, 1280);

  fill(95, 158, 160);

  rect(0, height/5, width, height*4/5);

  textSize(height/10);
  frameRate(90);
  fill(255);
  text("1", 30, height/5*1.7);
  text("2", 30+175, height/5*1.7);
  text("3", 30+175+175, height/5*1.7);
  text("+", 30+175+175+175, height/5*1.7);

  text("4", 30, height/5*2.7);
  text("5", 30+175, height/5*2.7);
  text("6", 30+175+175, height/5*2.7);
  text("-", 30+175+175+175, height/5*2.7);

  text("7", 30, height/5*3.7);
  text("8", 30+175, height/5*3.7);
  text("9", 30+175+175, height/5*3.7);
  text("x", 30+175+175+175, height/5*3.7);

  text("C", 30, height/5*4.7);
  text("0", 30+175, height/5*4.7);
  text("=", 30+175+175, height/5*4.7);
  text("/", 30+175+175+175, height/5*4.7);
}
void draw() { //ekran
  fill(255);
  rect(0, 0, width, height/5);
  fill(220, 20, 60);
  if (drawResult) {
    text(nfc(result,3), 30, 150);
  } else {
    text(input, 30, 150);
  }
}

void mousePressed() {

  if (mouseX >= 0 && mouseX <= 175 && mouseY >= height/4 && mouseY<= height/4+255 ) {
    input = input +1;
    drawResult = false;
  } else if (mouseX >= 175 && mouseX <= 0+175+175 && mouseY >= height/4 && mouseY<= height/4+255) {
    input = input +2;
    drawResult = false;
  } else if (mouseX >= 0+175+175 && mouseX <= 0+175+175+175 && mouseY >= height/4 && mouseY<= height/4+255) {
    input = input +3;
    drawResult = false;
  } else if (mouseX >= 0+175+175+175 && mouseX <= 0+175+175+175+175 && mouseY >= height/4 && mouseY<= height/4+255) {
    println("+");
    drawResult = false;
    input1 = parseInt(input);
    input = "+";
    operator = 1;
    //noStroke();
    //fill(255);
    //rect(0, 0, width, height/4);
    // rad 2
  } else if (mouseX >= 0 && mouseX <= 175 && mouseY >= height/4+255 && mouseY<= height/4+255+255) {
    input = input +4;
    drawResult = false;
  } else if (mouseX >=175 && mouseX <= 175+175 && mouseY >= height/4+255 && mouseY<= height/4+255+255 ) {
    input = input +5;
    drawResult = false;
  } else if (mouseX >= 175+175 && mouseX <= 175+175+175&& mouseY >= height/4+255 && mouseY<= height/4+255+255 ) {
    input = input +6;
    drawResult = false;
  } else if (mouseX >= 175+175+175 && mouseX <= 175+175+175+175&& mouseY >= height/4+255 && mouseY<= height/4+255+255 ) {
    println("-");
    drawResult = false;
    input1 = parseInt(input);
    input = "-";
    //fill(255);
    //rect(0, 0, 667, 212);
    //input = input + "-";
    operator = 2;

    //rad 3
  } else if (mouseX >= 0 && mouseX <= 175&& mouseY >= height/4+255+255 && mouseY<= height/4+255+255+255 ) {
    input = input +7;
    drawResult = false;
  } else if (mouseX >= 175 && mouseX <= 175+175 && mouseY >= height/4+255+255 && mouseY<= height/4+255+255+255 ) {
    input = input +8;
    drawResult = false;
  } else if (mouseX >= 175+175 && mouseX <= 175+175+175 && mouseY >= height/4+255+255&& mouseY<= height/4+255+255+255 ) {
    input = input +9;
    drawResult = false;
  } else if (mouseX >= 175+175+175 && mouseX <= 175+175+175+175 && mouseY >= height/4+255+255 && mouseY<= height/4+255+255+255 ) {
    println("x");
    drawResult = false;
    input1 = parseInt(input);
    input = "x";
    //fill(255);
    //rect(0, 0, 667, 212);
    operator = 3;

    //rad 4
  } else if (mouseX >= 0 && mouseX <= 0+175 && mouseY >= height/4+255+255+255 && mouseY<= height/4+255+255+255+255+255 ) {
    println("C");
    drawResult = false;
    input = "";
    input1 = 0;
    input2 = 0;
    operator = 0;
    //fill(255);
    //rect(0, 0, 665, 200);
  } else if (mouseX >= 175 && mouseX <= 175+175 && mouseY >= height/4+255+255+255&& mouseY<= height/4+255+255+255+255+255) {
    input = input +0;
  } else if (mouseX >= 175+175 && mouseX <= 175+175+175 && mouseY >= height/4+255+255+255 && mouseY<= height/4+255+255+255+255+255 ) {
    println("=");
    input2 = parseInt(input.substring(1)); //.substring(1) removes 1 symbol from the text
    input = input + "=";
}
else if (mouseX >= 175+175+175 && mouseX <= 175+175+175+175 && mouseY >= height/4+255+255+255 && mouseY<= height/4+255+255+255+255+255 ) {
   
    println("/");
    drawResult =false;
    
    input1= parseInt(input.substring(1));
    input = "/";
    
    input = input + "";
    operator = 4;
  }
    //fill(255);
    //rect(0, 0, 900, 300);
    //fill(220,20,60);
    if (operator == 1) {
      result = input1 + input2;
    } else if (operator == 2) {
      result = input1 - input2;
    } else if (operator == 3) {
      result = input1 * input2;
    } else if (operator == 4) {
      result = input1 / input2;
    }
    drawResult = true;
    input = "";
    input1 = 0;
    input2 = 0;
    operator = 0;
  } 
  println(input);
}

```

---

<div class="post-metadata">

### Author: ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)
#### Post date: [January 4, 2019, 10:33pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/2 "2019-01-04T22:33:23Z")

</div>

The reason your code isn’t running is because some code isn’t contained within a function, such as draw();

If you delete the last two lines:

```auto
println(input);
}

```

or move the _println()_ statement into draw then the code works fine

---

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 10:37pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/3 "2019-01-04T22:37:27Z")

</div>

Thank you can you make for me because my divided symbol is not work i work until six hour for it i am beginner it my fors project

---

<div class="post-metadata">

### Author: ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)
#### Post date: [January 4, 2019, 10:38pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/4 "2019-01-04T22:38:32Z")

</div>

**Also** a lot of your visuals are still contained in the setup function, which will only draw once. I would move pretty much everything in _setup()_ to _draw()_ (_except_ the _size()_, _textSize()_ and _frameRate()_ function)

---

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 10:41pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/5 "2019-01-04T22:41:36Z")

</div>

If you can write it i will very happy i have to make until morning

---

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 10:47pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/7 "2019-01-04T22:47:33Z")

</div>

I know but divided button is not work i tried for example 9/3 it show infinity answer of this problem

---

<div class="post-metadata">

### Author: ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)
#### Post date: [January 4, 2019, 11:03pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/8 "2019-01-04T23:03:49Z")

</div>

It looks like there’s no code that is setting input2 equal to any number, so the denominator will always be zero (hence infinity)

---

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 11:06pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/9 "2019-01-04T23:06:46Z")

</div>

> [@BennyHacker](#):
>
> equal

How i can add divide ?

---

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 11:09pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/10 "2019-01-04T23:09:31Z")

</div>

So how i can make input 2

---

<div class="post-metadata">

### Author: ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)
#### Post date: [January 4, 2019, 11:15pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/11 "2019-01-04T23:15:22Z")

</div>

What are you running this code on? It is too big to fit my screen and I cannot test

---

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 11:19pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/12 "2019-01-04T23:19:38Z")

</div>

I make for my cellphone if you make with pc it can be too big if you write i can test and i can say yo

---

<div class="post-metadata">

### Author: ![bossofeng](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bossofeng](https://discourse.processing.org/u/bossofeng)
#### Post date: [January 4, 2019, 11:20pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/13 "2019-01-04T23:20:22Z")

</div>

I hope you can help me i have to finish until this morning.

---

<div class="post-metadata">

### Author: ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)
#### Post date: [January 4, 2019, 11:23pm UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/14 "2019-01-04T23:23:17Z")

</div>

Oh ok. Well I was wrong about the input2 thing because I noticed you actually do have code for this. I would print input2 after parsing the ordinary input text and test different numbers. If the result is always 0 then it may be a problem with parsing

```auto
println("=");
    input2 = parseInt(input.substring(1)); //.substring(1) removes 1 symbol from the text
    println(input2);
    input = input + "=";

```

If this is the case then try adding a _radix_ to your parseInt()

input2 = parseInt(input.substring(1), **10** ); //.substring(1) removes 1 symbol from the text

---

<div class="post-metadata">

### Author: ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)
#### Post date: [January 5, 2019, 7:15am UTC](https://discourse.processing.org/t/basic-calculator-code-error-it-looks-like-you-are-mixing-active-and-static-modes/7194/15 "2019-01-05T07:15:32Z")

</div>

Oh. It’s actually a problem I’ve introduced into their code by helping them in another thread by adding `.substring(1)` to the code above, so that input2 can be `+3` or `-3` or `x3` or `/3` and each would be parsed as `3`, yet I didn’t notice that they don’t actually add the `/` symbol, so it gets sent as `3`, goes through `.substring(1)` that removes the first and only character, turns into nothingness, which is then parsed as 0.

Solution?

Make your code for `/` (divide) set `input` as `/`, exactly the same way other `+ - x` functions do it.

Try figuring that out yourself! You gotta start somewhere doing that and not have other people write it for you, isn’t that right? 😃
