View unanswered posts | View active topics It is currently Mon May 02, 2016 1:57 am

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
C order of Operations: is there an RobotC operator for ±?
Author Message
Rookie

Joined: Thu Mar 13, 2014 6:12 am
Posts: 43
C order of Operations: is there an RobotC operator for ±?
Hello all,

Just wondering if there is an operator symbol, in RobotC, for ±? I couldn't find one on the RobotC Wiki C order of operations page, but I thought I would just make sure. Just incase there is another way of doing this, anyways, this is the code I want to simplify, in Pseudo/RobotC code first, and pure RobotC second. The RobotC version is how I beleive it would otherwise have to be written. (All variables are of 'int' type)

 Code://Pseudo/RobotCif(var1 == (var2 ± 5) && var3 == (var2 ± 5))     /*in english: if 'var1' is within a range of 5 around 'var2', and 'var3' is also within a range of 5 around 'var2'*/{}

 Code://RobotCif(var1 < (var2 + 5) && var1 > (var2 - 5)){if(var3 < (var2 + 5) && var3 > (var2 - 5)){}}

EDIT: (I'll edit this message, rather then re-posting, so that it still registers as unanswered - which it is!)

I'm just wondering about the ± operation, because otherwise I have to do this (I'm not sure that it works, because it has && and ||!):
 Code://green is 'int', green2 is 'bool', green3 is 'bool', and lght2 and lght3 are the respective S2 and S3.if((SensorValue(lght2) < green + 5 && SensorValue(lght2) > green - 5 && green2) || (SensorValue(lght3) < green + 5 && SensorValue(lght3) > green - 5 && green3))

_________________
- PacTeam

Sat Jul 19, 2014 5:47 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: C order of Operations: is there an RobotC operator for ±
No, ROBOTC does not have that specific operator. I am pretty sure that it does not exist in ANSI C or C++ either. I am not sure I could even type it on this keyboard without resorting to either copying and pasting or ALT-keypadnumbers.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Sat Jul 19, 2014 9:58 am
Professor

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Re: C order of Operations: is there an RobotC operator for ±
There is another way you could do it using the abs function. Something like:
 Code:abs(green - SensorValue[light2]) < 5

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.

Sat Jul 19, 2014 2:31 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning