View unanswered posts | View active topics It is currently Fri May 24, 2019 2:51 pm






Reply to topic  [ 3 posts ] 
Arrays in RobotC 
Author Message
Rookie

Joined: Sat Jan 02, 2016 5:22 am
Posts: 2
Post 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? :-)


Sat Jan 02, 2016 5:36 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: Arrays in RobotC
Please post the code you have so we could help you.
Try to use the code format if you can.


Sat Jan 02, 2016 11:49 pm
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post 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?


Fri Jan 08, 2016 1:48 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.