Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,431 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,906 people online right now. Registration is fast and FREE... Join Now!




making a variable not equal to a value

 
Reply to this topicStart new topic

making a variable not equal to a value

scudder5000
18 Jan, 2008 - 11:44 PM
Post #1

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 9


My Contributions
i want to know if it is possible to to make x not equal to a value instead of equal to a value.
CODE
x=5;
i know works.
i want to know if this code will work.
CODE
x !=5;

if it does work can x be made not equal to multiple values. like
CODE
x != 5; && x !=6;

thank you for your time.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Making A Variable Not Equal To A Value
18 Jan, 2008 - 11:51 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,260



Thanked: 227 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
No the code x != 5 will not work in the context you are asking. That is because != is a test of inequality, not one of assignment. What typically you do is list all the values you want to check against and then compare X to this list. If it is found, switch it to a value you know is not in the list, or assign it a new value and again check it against the list of excluded values.

How you do this can be numerous. You could use an array of "bad values" and loop through it. You could use a string of values and do a sub string search, you simply test it against each value in a nested if or even in a switch case if you wanted to (where you would setup the "default" case to be the ideal situation where it matched no cases).

It is up to you on which solution you want based on your problem domain. But it is all about the design.

I hope that answered your question. smile.gif

"At DIC we be value testing code ninjas, so how much do you value your life?" decap.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 04:58AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month