user76606: I am new to Arduino and C++ and I was practicing with a traffic light project.
This is my code:
int red = 10;
int yellow = 9;
int green = 8;

void setup() {
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(green,OUTPUT);
}

void loop() {
  changelights();
  delay (15000);
}

void changelights{
  // 1st action: green off to yellow
  digitalWrite(green, LOW);
  digitalWrite(yellow, HIGH);
  delay (3000)
  // 2nd action: tellow to red 
  digitalWrite(yellow, LOW);
  digitalWrite(red, HIGH);
  //3rd action: caution light 
  digitalWrite(yellow, HIGH);
  delay (3000)
  //4th action: caution to go 
  digitalWrite(red,LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(green, HIGH);
}

I tried compiling it and returned an error message that said that I did not declare my "changelights" function. What should I do to fix this?
Thank you very much

user68788: You forgot to put the parenthenses () after the name of the function changelights. They are there to declare variables you can use later in the code like that:
void function(int a){
  a+=1;
  return a;
}

To fix your error just change
void changelights{

to
void changelights(){

Keep in mind if you want to program C++ (which would be Off-Topic here, but you mentioned it in your question) you have to declare the function in the beginning or mention it.

76606: <p>I am new to Arduino and C++ and I was practicing with a traffic light project.</p>
<p>This is my code:</p>
<pre class="lang-cpp prettyprint-override"><code>int red = 10;
int yellow = 9;
int green = 8;

void setup() {
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(green,OUTPUT);
}

void loop() {
  changelights();
  delay (15000);
}

void changelights{
  // 1st action: green off to yellow
  digitalWrite(green, LOW);
  digitalWrite(yellow, HIGH);
  delay (3000)
  // 2nd action: tellow to red 
  digitalWrite(yellow, LOW);
  digitalWrite(red, HIGH);
  //3rd action: caution light 
  digitalWrite(yellow, HIGH);
  delay (3000)
  //4th action: caution to go 
  digitalWrite(red,LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(green, HIGH);
}
</code></pre>
<p>I tried compiling it and returned an error message that said that I did not declare my &quot;changelights&quot; function. What should I do to fix this?</p>
<p>Thank you very much</p>
 68788: <p>You forgot to put the parenthenses <code>()</code> after the name of the function <code>changelights</code>. They are there to declare variables you can use later in the code like that:</p>
<pre class="lang-cpp prettyprint-override"><code>void function(int a){
  a+=1;
  return a;
}
</code></pre>
<p>To fix your error just change</p>
<pre class="lang-cpp prettyprint-override"><code>void changelights{
</code></pre>
<p>to</p>
<pre class="lang-cpp prettyprint-override"><code>void changelights(){
</code></pre>
<p>Keep in mind if you want to program C++ (which would be Off-Topic here, but you mentioned it in your question) you have to declare the function in the beginning or mention it.</p>
