I am just starting to learn C++ and I am getting a "does not name a type" errors. I have gotten this when I try to print and also when I just copy and paste working code only changing the names of the constants.
{sigh} Show us the code. Use code tags.
Show us the error messagses.
Model RR. 3 IR sensors on a loop and I need to read each to determine where train is.
The error says Type B "does not name a type".
int Rled = 4;
int Bled = 3;
int Yled = 2;
int Asens = 9; //Input from A
int Bsens = 11; //Input from B
int Csens = 10; //Input from C
int TempA = HIGH; //Temp storage for Asens
int TempB = HIGH; //Temp storage for Bsens
int TempC = HIGH; //Temp storage for Csens
void setup() {
pinMode(Rled, OUTPUT);
pinMode(Bled, OUTPUT);
pinMode(Yled, OUTPUT);
pinMode (Asens, INPUT);
pinMode (Bsens, INPUT);
pinMode (Csens, INPUT);
Serial.begin(9600);
}
void loop() {
TempA = digitalRead(Asens);
if (TempA == LOW)
{
Serial.println("What is this Obstacle on A?");
digitalWrite(Rled, HIGH);
}
else
{
Serial.println("No Obstacle");
digitalWrite(Rled, LOW);
}
delay(1200); }
TempB = digitalRead(Bsens);
if (TempB == LOW)
{
Serial.println("What is this Obstacle?");
digitalWrite(Bled, HIGH);
}
else
{
Serial.println("No Obstacle");
digitalWrite(Bled, LOW);
}
delay(1200); }
TempB = digitalRead(Bsens);
if (TempB == LOW)
{
Serial.println("What is this Obstacle on B?");
digitalWrite(Rled, HIGH);
}
else
{
Serial.println("No Obstacle");
digitalWrite(Rled, LOW);
}
delay(1200); }
TempC = digitalRead(Bsens);
if (TempC == LOW)
{
Serial.println("What is this Obstacle on C?");
digitalWrite(Yled, HIGH);
}
else
{
Serial.println("No Obstacle");
digitalWrite(Yled, LOW);
}
delay(1200); }
It says a whole lot more than that, but you couldn't be bothered to do a simple cut-and-paste.
Please remember to use code tags when posting code
I was asking for help, not a smart ass reply!
So, it doesn't say "Type B "does not name a type"." at all, does it?
These { and these } belong on their own lines. It helps make the boo-boos more obvious
Edit: you were asking for help, but not helping yourself get it. Good luck with that attitude.
Common compiler errors caused by mismatched brackets:
"does not name a type" or
"expected declaration before" or
"expected unqualified-id before" or
"expected initializer before" or
"expected constructor, destructor, or type conversion before '(' token"
Usually means you forgot a '{' or put in an extra '}' in the previous function. Since all of the open brackets have been closed, the compiler is looking for further global declarations (variables or functions). If it finds something that looks like executable code instead of a global declaration it emits an error. Make sure that the brackets in the preceding function are in matching pairs '{' followed by '}'.
"a function-definition is not allowed here before '{' token"
(can cause: "'functionName' was not declared in this scope")
Usually means you forgot a '}' or put in an extra '{' in the previous function. Since a set of brackets has not been closed yet the compiler is looking for more code to put in the function. You can't declare a function inside a function so if the compiler finds a function declaration it emits an error. Make sure that the brackets in the preceding function are in matching pairs '{' followed by '}'.
"expected '}' at end of input"
Usually means you forgot a '}' or put in an extra '{' in the last function in the sketch. Since a set of brackets has not been closed yet, the compiler is looking for more code to put in the function. When it hits the end of the file instead, it emits an error. Make sure that the brackets in the last function are in matching pairs '{' followed by '}'.
"expected primary-expression before '}' token"
Usually means you have an incomplete statement before a '}'. The block statement (between '{' and matching '}') can only contain complete statements. Complete statements always end with ';' (or '}' for a block statement).
Thank you. Those "curly" brackets can make a person crazy.
There is no reason for TempA, TempB or TempC to have global scope.
The pin number constants should be "const" and be of type "byte"
Another BIG thank you! I fixed it at your suggestion. I am an old hardware guy (Univac and Control Data) starting 1959.