ROBOTC.net forums
http://robotc.net/forums/

Arrays in RobotC
http://robotc.net/forums/viewtopic.php?f=1&t=13033
Page 1 of 1

Author:  hehahe [ Sat Jan 02, 2016 5:36 am ]
Post subject:  Arrays in RobotC

Hello!
The robot has one wheel at the back and this wheel is attached to a motor. It drives forward and if i would clap once, it would turn left. If I would clap two times it would go right and three times would mean that the wheel would go back straight. I have created an array for this that counts number of claps. If i clap once there is one variable in an array, two times there are two and so on. The problem is that then i have to check how many of these variables the array contains but i don't know how to do this. Can somebody help me with this? :-)

Author:  CARBOT [ Sat Jan 02, 2016 11:49 pm ]
Post subject:  Re: Arrays in RobotC

Please post the code you have so we could help you.
Try to use the code format if you can.

Author:  Tabor473 [ Fri Jan 08, 2016 1:48 pm ]
Post subject:  Re: Arrays in RobotC

hehahe wrote:
Hello!
The robot has one wheel at the back and this wheel is attached to a motor. It drives forward and if i would clap once, it would turn left. If I would clap two times it would go right and three times would mean that the wheel would go back straight. I have created an array for this that counts number of claps. If i clap once there is one variable in an array, two times there are two and so on. The problem is that then i have to check how many of these variables the array contains but i don't know how to do this. Can somebody help me with this? :-)

Okay so to answer your question the simplest is going to be a for loop, a for loop is a limited loop that is designed to run a discrete number of times while maintaining the count of its location as it parses.
Code:
task main()
{
   const int arrayLength=5;
   int counter;
   int toParse[arrayLength] = {0,0,0,0,0};

   for(int i=0;i<arrayLength;i++){
      if(toParse[i]!=0)
         counter++;
   }


}

My question is there a reason you don't just use whatever counts the claps to increment a variable directly rather than fill the array? I guess the question is do you plan on using the values in the array or just the fact that you put something there?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/