# Help, code expecting EOF, found '}'

**URL:** <https://discourse.processing.org/t/help-code-expecting-eof-found/26444>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 22, 2020, 1:40pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444 "2020-12-22T13:40:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dialias](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@Dialias](https://discourse.processing.org/u/Dialias)\
**Post date:** [December 22, 2020, 1:40pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444/1 "2020-12-22T13:40:30Z")

</div>

int money;  
PImage pic1;  
PImage pic2;

int rx1 = 250;  
int ry1 = 200;  
int rwidth1 = 280;  
int rheight1 = 140;

int rx2 = 600;  
int ry2 = 600;  
int rwidth2 = 780;  
int rheight2 = 780;

void setup() {

size(800, 600);

money = 0;

pic1 = loadImage(“foto\_1.png”);  
pic2 = loadImage(“foto\_2.png”);

noStroke();  
}  
void mousePressed() {  
if (rx1 \<= mouseX && mouseX \<= rx1 + rwidth1 &&  
ry1 \<= mouseY && mouseY \<= ry1 + rheight1) {  
money = money + 1;  
}  
{  
if (rx2 \<= mouseX && mouseX \<= rx2 + rwidth2 &&  
ry2 \<= mouseY && mouseY \<= ry2 + rheight2);  
money \>=10 = money - 10;  
{  
fill(100, 0, 0);  
rect(600, 200, 780, 780);  
}  
}  
}  
} e{lse fill(230);  
rect(600, 200, 780, 780);

}  
void draw() {  
background(200);  
println(money);  
textSize(32);  
fill(0);  
image(pic1, 100, 15);  
pic1.resize(0, 80);  
image(pic2, 250, 200);  
text(money, 50, 60);  
}

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 22, 2020, 1:57pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444/2 "2020-12-22T13:57:19Z")

</div>

Check your mousepressed function at first glance you have a typo at the last else statement.

---

<div class="post-metadata">

**Author:** ![Dialias](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@Dialias](https://discourse.processing.org/u/Dialias)\
**Post date:** [December 22, 2020, 2:40pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444/3 "2020-12-22T14:40:10Z")

</div>

@paulgoux  
i fixed it but yet there is expecting EOF, found ‘else’

int money;  
PImage pic1;  
PImage pic2;

int rx1 = 250;  
int ry1 = 200;  
int rwidth1 = 280;  
int rheight1 = 140;

int rx2 = 600;  
int ry2 = 600;  
int rwidth2 = 780;  
int rheight2 = 780;

void setup() {

size(800, 600);

money = 0;

pic1 = loadImage(“foto\_1.png”);  
pic2 = loadImage(“foto\_2.png”);

noStroke();  
}  
void mousePressed() {  
if (rx1 \<= mouseX && mouseX \<= rx1 + rwidth1 &&  
ry1 \<= mouseY && mouseY \<= ry1 + rheight1) {  
money = money + 1;  
}  
{  
if (rx2 \<= mouseX && mouseX \<= rx2 + rwidth2 &&  
ry2 \<= mouseY && mouseY \<= ry2 + rheight2);  
money \>=10 = money - 10;  
{  
fill(100, 0, 0);  
rect(600, 200, 780, 780);  
}  
}  
}  
else fill(230);  
rect(600, 200, 780, 780);

}  
void draw() {  
background(200);  
println(money);  
textSize(32);  
fill(0);  
image(pic1, 100, 15);  
pic1.resize(0, 80);  
image(pic2, 250, 200);  
text(money, 50, 60);  
}

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 22, 2020, 3:20pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444/4 "2020-12-22T15:20:14Z")

</div>

This is how your mousepressed should look. Also remember to format your code.

```auto
void mousePressed() {
if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 &&
ry1 <= mouseY && mouseY <= ry1 + rheight1) {
money = money + 1;

}
else if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 &&
ry2 <= mouseY && mouseY <= ry2 + rheight2){
money >=10 = money - 10;

fill(100, 0, 0);
rect(600, 200, 780, 780);
}
else{ fill(230);
rect(600, 200, 780, 780);

}
}

```

---

<div class="post-metadata">

**Author:** ![Dialias](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@Dialias](https://discourse.processing.org/u/Dialias)\
**Post date:** [December 22, 2020, 3:27pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444/5 "2020-12-22T15:27:56Z")

</div>

@paulgoux  
hey but yet there is ,unexoected token: void"

and i cant format my code.

```
intmoney;intowned1;

PImage pic3;  
PImage pic1;  
PImage pic2;

int rx1 = 250;  
int ry1 = 200;  
int rwidth1 = 280;  
int rheight1 = 140;

int rx2 = 600;  
int ry2 = 75;  
int rwidth2 = 800;  
int rheight2 = 125;

void **setup** () {

&nbsp;&nbsp;size(800, 600);

&nbsp;&nbsp;money&nbsp;=&nbsp;0;  
&nbsp;&nbsp;owned1&nbsp;=&nbsp;0;

&nbsp;&nbsp;pic1&nbsp;=&nbsp;loadImage(“foto\_1.png”);  
&nbsp;&nbsp;pic2&nbsp;=&nbsp;loadImage(“foto\_2.png”);  
&nbsp;&nbsp;pic3&nbsp;=&nbsp;loadImage(“foto\_3.png”);

&nbsp;&nbsp;noStroke();  
}  
void **mousePressed** () {  
&nbsp;&nbsp;if (rx1 \<= mouseX && mouseX \<= rx1 + rwidth1 &&  
&nbsp;&nbsp;&nbsp;&nbsp;ry1&nbsp;\<=&nbsp;mouseY && mouseY \<= ry1 + rheight1) {  
&nbsp;&nbsp;&nbsp;&nbsp;money&nbsp;=&nbsp;money&nbsp;+&nbsp;1;  
&nbsp;&nbsp;}&nbsp;else if (rx2 \<= mouseX && mouseX \<= rx2 + rwidth2 &&  
&nbsp;&nbsp;&nbsp;&nbsp;ry2&nbsp;\<=&nbsp;mouseY && mouseY \<= ry2 + rheight2) {  
&nbsp;&nbsp;&nbsp;&nbsp;money&nbsp;\>=10&nbsp;=&nbsp;money&nbsp;-&nbsp;10;

&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void **draw** () {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background(200);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;println(money);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textSize(32);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fill(0);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image(pic1, 100, 15);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pic1.resize(0, 80);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image(pic2, 250, 200);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pic3.resize(0, 80);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image(pic3, 650, 100);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text(money, 50, 60);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text(owned1, 650, 120);  
&nbsp;&nbsp;&nbsp;&nbsp;}
```

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 22, 2020, 5:33pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444/6 "2020-12-22T17:33:08Z")

</div>

To format code press CTRL + SHIFT + C.

youve made a change to the mousepressed function i posted though.

---

<div class="post-metadata">

**Author:** ![trackme518](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@trackme518](https://discourse.processing.org/u/trackme518)\
**Post date:** [December 22, 2020, 5:41pm UTC](https://discourse.processing.org/t/help-code-expecting-eof-found/26444/7 "2020-12-22T17:41:23Z")

</div>

```auto
int money;
int owned1;
PImage pic3;
PImage pic1;
PImage pic2;
int rx1 = 250;
int ry1 = 200;
int rwidth1 = 280;
int rheight1 = 140;
int rx2 = 600;
int ry2 = 75;
int rwidth2 = 800;
int rheight2 = 125;

void setup() {
  size(800, 600);
  money = 0;
  owned1 = 0;
  pic1 = loadImage("foto_1.png");
  pic2 = loadImage("foto_2.png");
  pic3 = loadImage("foto_3.png");
  noStroke();
}

void mousePressed() {
  if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 && ry1 <= mouseY && mouseY <= ry1 + rheight1) {
    money = money + 1;
  } else if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 && ry2 <= mouseY && mouseY <= ry2 + rheight2) {
    money = money - 10;
  }
}

void draw() {
  background(200);
  println(money);
  textSize(32);
  fill(0);
  image(pic1, 100, 15);
  pic1.resize(0, 80);
  image(pic2, 250, 200);
  pic3.resize(0, 80);
  image(pic3, 650, 100);
  text(money, 50, 60);
  text(owned1, 650, 120);
}

```
