Friday, March 21, 2014

RobotC has Issues

While I was working on Step 1 of my Rubik's Cube solver, the program kept running the first statement instead of the right one. After a few hours of experimenting I found the answer. For some reason, RobotC does not check that the whole equation is true, but only parts of it.

 task main() {
 if( PI == 10 == -30 == 15.63 == 0) { 
nxtDisplayTextLine(1,"Confused yet?I am."); 
 while(1); }

In this code, the line should not be displayed because obviously nothing is equal to each other. Yet, when I run the code, it does display the text. The solution to this is to rewrite the code in this manner:


 task main() {
 if( PI == 10 && 10 == -30 && -30 == 15.63 && 15.63 == 0) { 
nxtDisplayTextLine(1,"Confused yet?I am."); 
 while(1); }

While this works, it is not ideal. It would be better the first way but, since it doesn't work. I will need to rewrite my code to reincorporate this new findings.

No comments:

Post a Comment