attachinterrupt expected primary-expression before 'switch'


I'm really new to coding. For a schoolproject I need to measure whenever there is a voltage change on a pin, and need to increase a variable. However, I keep getting the same error, and I don't know how to solve it. Please see my code below. Does anyone of you know a solution to my problem?

const byte pinX = 2;
int StageCount = 0;
void setup() {
  pinMode(pinX, INPUT); //set pin 2 as input for phototransistor
  attachInterrupt(digitalPinToInterrupt(pinX), switch, CHANGE);

int switch() {
  if(digitalRead(pinX == HIGH) {

All program code must be in a function. Most of yours isn't

Another thing. Where is the loop function ?

Since "switch" is already a keyword in C, I might avoid naming my function the same, although, technically, switch() and switch are different. However, you cannot use switch (switch() might be ok) in your attachInterrupt() construct.