Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Limiting variable between 2 number
 User Name Remember Me? Password

Before you post, read our: Rules & Posting Guidelines

 Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-16-2005, 09:23 PM PM User | #1 west_dweller79 New Coder   Join Date: Feb 2005 Posts: 18 Thanks: 0 Thanked 0 Times in 0 Posts Limiting variable between 2 number Dear all, My program have 4 directional switches with the value shown below: up = -2 right = -3 down = -5 left = -9 I'll to write something like........ switch = read_switch(); count = 1; if(switch==-3) { count++; } if(switch==-9) { count--; } switch(count); { case '1': printf("........"); break; case '2': printf("........"); break; case '3' printf("........."); break; } Is it possible to limit the count between 1 and 3 (mimimum is 1 and maximum is 3 no matter how many 'left' or 'right' i press), so that the program will display something. Cause if i don't limit 'count', 'count' will also increase/decrease by the amount of time i pressed. Value of count does no change when i press 'up' or 'down'. Hope you get wat i mean Thanks in advance west_dweller
 02-17-2005, 08:54 AM PM User | #2 Dr. Evil New Coder   Join Date: Nov 2004 Location: Netherlands Posts: 87 Thanks: 0 Thanked 0 Times in 0 Posts It depends on how you want to limit it, if it will go back to zero after hitting 3, then you could use the modulus operator, but if you want it to stay at three when it hits it, then a simple check could be implemented. By the way, I think you'll have to change the name of your variable 'switch', for it interferes with a C keyword.
 02-19-2005, 01:23 AM PM User | #3 Dunna Regular Coder   Join Date: May 2004 Location: New Hampshire, America Posts: 245 Thanks: 0 Thanked 2 Times in 2 Posts Code: ```if(switch==-3) { count++; } if(switch==-9) { count--; } if (count <= 1) count++; if (count >= 3) count--; switch(count); { case '1': printf("........"); break; case '2': printf("........"); break; case '3' printf("........."); break; }``` As Dr. Evil said, you are definetly going to have to switch that switch, if you catch my meaning. (If I misread the question, my apologies) Last edited by Dunna; 02-19-2005 at 01:26 AM..

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 12:57 PM.

 AdvertisementLog in to turn off these ads.