I have a basic problem i write a basic calculator it works but i pressed then equal symbol if i press a new number first answer stay there and new answer write up last answer my english not very well so i will upload a photo i hope you can help me
And my codes:
String input = "";
float input1 = 0;
float input2 = 0;
int operator = 0;
void setup() {
background(255);
size(720,1280);
fill(95, 158, 160);
rect(0, height/5, width, height);
textSize(height/10);
frameRate(90);
fill(255);
text("1", 20, height/4+20, width, height);
text("2", 20+175, height/4+20, width, height);
text("3", 20+175+175, height/4+20, width, height);
text("+", 20+175+175+175, height/4+20, width, height);
text("4", 20, height/4+255, width, height);
text("5", 20+175, height/4+255, width, height);
text("6", 20+175+175, height/4+255, width, height);
text("-", 20+175+175+175, height/4+255, width, height);
text("7", 20, height/4+255+255, width, height);
text("8", 20+175, height/4+255+255, width, height);
text("9", 20+175+175, height/4+255+255, width, height);
text("x", 20+175+175+175, height/4+255+255, width, height);
text("C", 20, height/4+255+255+255, width, height);
text("0", 20+175, height/4+255+255+255, width, height);
text("=", 20+175+175, height/4+255+255+255, width, height);
text("/", 20+175+175+175, height/4+255+255+255, width, height);
}
void draw() { //ekran
fill(220,20,60);
text(input, 30, 150);
}
void mousePressed() {
if (mouseX >= 0 && mouseX <= 175 && mouseY >= height/4 && mouseY<= height/4+255 ) {
input = input + 1;
} else if (mouseX >= 175 && mouseX <= 0+175+175 && mouseY >= height/4 && mouseY<= height/4+255) {
input = input +2;
} else if (mouseX >= 0+175+175 && mouseX <= 0+175+175+175 && mouseY >= height/4 && mouseY<= height/4+255) {
input = input +3;
} else if (mouseX >= 0+175+175+175 && mouseX <= 0+175+175+175+175 && mouseY >= height/4 && mouseY<= height/4+255) {
println("+");
input1 = parseInt(input);
input = "";
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;
} else if (mouseX >=175 && mouseX <= 175+175 && mouseY >= height/4+255 && mouseY<= height/4+255+255 ) {
input = input +5;
} else if (mouseX >= 175+175 && mouseX <= 175+175+175&& mouseY >= height/4+255 && mouseY<= height/4+255+255 ) {
input = input +6;
} else if (mouseX >= 175+175+175 && mouseX <= 175+175+175+175&& mouseY >= height/4+255 && mouseY<= height/4+255+255 ) {
println("-");
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;
} else if (mouseX >= 175 && mouseX <= 175+175 && mouseY >= height/4+255+255 && mouseY<= height/4+255+255+255 ) {
input = input +8;
} else if (mouseX >= 175+175 && mouseX <= 175+175+175 && mouseY >= height/4+255+255&& mouseY<= height/4+255+255+255 ) {
input = input +9;
} else if (mouseX >= 175+175+175 && mouseX <= 175+175+175+175 && mouseY >= height/4+255+255 && mouseY<= height/4+255+255+255 ) {
println("x");
input1 = parseInt(input);
input = "";
fill(255);
rect(0, 0, 667, 212);
input = input + "";
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");
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);
input = input + "=";
fill(255);
rect(0, 0, 900, 300);
fill(220,20,60);
if (operator == 1) {
text(int(input1 + input2), 30, 150);
operator = 0;
} else if (operator == 2) {
text(int(input1 + input2), 30, 150);
} else if (operator == 3) {
text(int(input1 * input2), 30, 150);
} else if (operator == 4) {
text(nf(input1 / input2,0,0), 30, 150);
if (input2 == 0)
;
}
input = "";
input1 = 0;
input2 = 0;
operator = 0;
} 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 ) {
input1 = parseInt(input);
input = "";
fill(255);
rect(0, 0, 667, 212);
input = input + "";
operator = 4;
}
println(input);
}