I have been working with this code for sometime and would like to turn it into a multi stage program. Once a person finds the place the box is suspose to be, I want to make it change to a different set of cords and have them to their and then change to another set of cords and so on.
Now I have started with the first switch and case #. It seems to complile just fine. But I am unsure as to where to place the "break" command. I did place it at where I wanted to break and it seems to compile. But when I start to place the "case 2:", I don't seem to be placing it in the correct location.
With it in the current location I get, "SlimJim_Inverse_Stages_and_switches:340: error: expected unqualified-id before 'case'".
I have tried searching for info, but I get more searchers about C++ than anything else and I can't really make out the differences.
switch ( random('a', 'z') )
{
case 'a':
... some useful code here ...
break;
case 'b':
... some useful code here ...
break;
case 'c':
... some useful code here ...
break;
case 'd':
... some useful code here ...
break;
case 'd':
case 'e':
case 'f':
case 'q':
... some useful code here ...
break;
default:
// handle all other values ...
break;
}
"In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. "
The examples show case 1, case 2, and I know case 'a', case 'b' work also.
"In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. "
The examples show case 1, case 2, and I know case 'a', case 'b' work also.
No I'm not trying to be deliberately obscure. I'm sorry if it came across like that. It would be just my lack of know how. Another suggestion was to put things into different functions because of the massive amount of code that i already have. Then use the switch cases to call those functions.
What do you suggest using with the switch statements other than 1,2 and so on. I am working with a multi stage Geocache and was going to use stage 1 then stage 2 and so on. I so far have been able to have the "stages" change like I want them to. Or so I think I do.
michinyon:
Even if the compiler accepts it, coding a switch statement with 1,2,'A', ... is simply unwise programming.
It is difficult to figure out what it will do. Unless you are trying to be deliberately obscure.
Thank you for looking at the code. I removed the Case 2 because of the error and started with that. I try building the functions and try calling them from there. I just have to figure out how in incorporate some of the code from the void setup into the void loop/function call.
CrossRoads:
I only see a Case 1, it looks good to start.
Well I changed the orginal loop to a function and then created a new loop and added the switches and case numbers to it. Everything complies just find with no errors. But when I upload load, the arduino gets to the end of the void setup and then stops. It doesn't seem to get into the void loop.
I even tried adding a "default" thinking it might would use that, but it doesn't.