0

I'm trying to experiment with a "return" function. Yet each time I try to run my program, there happens to be an error, like "expected declaration before '}' token."

Can someone explain the basics of a return function, and look at my code below to possibly see what the problem could be?

{
int index;
pinMode(10, INPUT); //button input
int checkInput();
if (digitalRead(10) == 0) {
return 1;
else{
return 0;
 }
}
asked Mar 25, 2016 at 22:40
2
  • What is the line int checkInput(); supposed to achieve? Commented Mar 25, 2016 at 23:38
  • return isn't a function, it's a statement. In case the answers didn't make it clear, you change int checkInput(); to checkInput(); Commented Mar 26, 2016 at 6:45

2 Answers 2

3

It has nothing to do with the retun statements. You have to close each { with a }. you are missing one.

 {
int index;
pinMode(10, INPUT); //button input
int checkInput();
if (digitalRead(10) == 0) {
return 1;}
else{
return 0;
 }
}
answered Mar 25, 2016 at 23:06
3

That piece of "code" is, I am afraid to say, complete gibberish.

Passed through Artistic Style to reformat it ends up with:

{
 int index;
 pinMode(10, INPUT); //button input
 int checkInput();
 if (digitalRead(10) == 0) {
 return 1;
 else {
 return 0;
 }
 }

Starting from the top of the program the errors are:

  1. You have a bracket hanging at the front of the snippet for some reason
  2. int checkInput(); is a function prototype (forward declaration) and doesn't do anything other than tell the compiler that you will define this function somewhere else in your sketch.
  3. You are lacking the balancing bracket for the first portion of your if statement, so your else { return 0; } never runs.
  4. There is no balancing bracket for the strange one by itself at the start of the snippet.

In short, I have a feeling you need to learn the basics of C syntax.

answered Mar 25, 2016 at 23:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.