This program takes input from 2 touch sensors; where you have to Click the First touch sensor (1 or 2 times) then the Second touch sensor (1 or 2 times)
If the first touch sensor pressed 1 time -->it will move 1 meter
If the first touch sensor pressed 2 times --> it will move 2 meters
If the Second touch sensor pressed 1 time --> it will move 5 meters
If the Second touch sensor pressed 2 times --> it will move 10 meters
Your code is complicated enough that it makes it hard to say exactly what it going wrong. And I can't test it myself without a lot of work and I don't know exactly what you have in mind for the "correct" behavior. I think it would help you and us if you were to write down in plain old English exactly what you want your program to do. Also tell us what you mean by "it seems like it doesn't work". What does it do?
what if you try it to "say" it by
if...
else if....
else if...
else if...
?
(just the way you wrote it down in your pseudo-language schedule?
just remember:
KISS -
keep it simple and stupid.)
afanofosc wrote:Your code is complicated enough that it makes it hard to say exactly what it going wrong. And I can't test it myself without a lot of work and I don't know exactly what you have in mind for the "correct" behavior. I think it would help you and us if you were to write down in plain old English exactly what you want your program to do. Also tell us what you mean by "it seems like it doesn't work". What does it do?
John Hansen
ok I will try ^^ plz bear with me coz I need this Exact methodology for a bigger project ^-^
--begin--
define two int conter1 & counter2 < (the sum of counters (number of how many the touch sensor was pressed)
Claculate Number of times the first touch sensor is pressed --(assign to)-->touchCounter1
Calculate Number of times the Second touch sensor is pressed --(assign to)--> touchCounter2
-------------> till this step the program worked ...but it didn't go to switch I don't know why
Switch (touchCounter1):
case 1 //( first touch sensor pressed once => 1 m)
{
Switch (touchCounter2):
{
case 1 //(second touch sensor pressed once => 5 m)
Robot move 6 m forward // 1 m + 5 m ;
case 2 // (second touch sensor pressed twice => 10 m)
Robot move 11 m forward // 1 m + 10 m ;
} //end switch
case 2 // ( Second touch sensor pressed twice => 2 m)
{
Switch (touchCounter2):
{
case 1 //(second touch sensor pressed once => 5 m)
Robot move 7 m forward // 2 m + 5 m ;
case 2 // (second touch sensor pressed twice => 10 m)
Robot move 12 m forward // 2 m + 10 m ;
} //end switch
I think if else if would work , but I need to learn how to do it with switch ^_^
int meters = -1;
switch( counter1 ){
case 0:
switch( counter2 ){
case 0: meters = 0; break;
case 1: meters = 5; break;
case 2: meters = 10; break;
}
break;
case 1:
switch( counter2 ){
case 0: meters = 1; break;
case 1: meters = 6; break;
case 2: meters = 11; break;
}
break;
case 2:
switch( counter2 ){
case 0: meters = 2; break;
case 1: meters = 7; break;
case 2: meters = 12; break;
}
break;
}
Notice what happens if either Touch 1 or Touch 2 happens to be pressed more than twice. None of the cases are activated, so 'meters' didn't change and is still '-1'.
So I didn't look closely enough but in C the keywords are case sensitive - "case" vs "Case" and each case falls through to the next case unless you use "break;" so that could be part of your problem. Look up the correct C syntax for "switch" in the NXC help or anywhere online using Google.