Running first 6 digits of fibonacci

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}
int main(){
}; int x
int a;
int b;
int c;

x=0;
a=0;
b=0;
c=1;

a=b+c;
b=c;
c=a;
x=x+1;
when x>5;
return 0;
}
exit status 1
expected initializer before 'int'
this error occurs before int a
Can anyone help

Your error is because there's no semicolon after "int x", but that's the least of your problems.

I found this

The posted code just needs a little syntax cleanup:

int x;
int a;
int b;
int c;

void setup() {
  // put your setup code here, to run once:
 x=0;
 a=0;
 b=0;
 c=1;
// maybe Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

 a=b+c;
 b=c;
 c=a;
  x=x+1;

 // maybe Serial.println (a);  // want to see some output?
   if (x<6){
  // make another pass thru loop
  }
  else {
  while(1); // do nothing until reset is pressed
  }
}

Thanks! what does serial mean? and also what is serial.begin(9600)? Thanks

Serial.begin() and Serial.print() or Serial.println() are how you display stuff on the Serial monitor in the IDE.

Thanks! however, the line a=b+c says that a does not specify a type.

We can't see your code.

int x;
int y;
int b;
int c;
void setup() {
// put your setup code here, to run once:
x=0;
y=0;
b=0;
c=1;
}

void loop() {
// put your main code here, to run repeatedly:

}y=b+c;
b=c;
c=y;
x=x+1;
when (x<6);{
return 0;

Serial.println(y)
else{
while(1);
}

the problem is that y=b+c is returning error y does not name a type

The } just in front of the y ends loop() and so everything from there onwards is not in any function.

int x;
int y;
int b;
int c;
void setup() {
// put your setup code here, to run once:
x=0;
y=0;
b=0;
c=1;
}

void loop() {
// put your main code here, to run repeatedly:

y=b+c;
b=c;
c=y;
x=x+1;
if (x<6);{
return 0;

Serial.println(y)
;}
else{
while(1);
}

it is now returning that else has no if. why would this occur?

if (x<6);{

You should look up the syntax of if (and C++ in general).

Starting late on the homework?

Some general tips:

  • use sensible variable names
  • use Serial.begin() if you want to use Serial
  • put code to run once into setup
  • only make variables global if they have to be shared
  • don't try to return values from void functions