0

For CS50 pset1 Credit I'm using repeated logical-OR operators (||) to work out the validity and card brand of a credit card number. When I evaluate the style of my code using style50 it says to insert a new line in the longest series of these logical operators. Is there a way of reducing the length of these altogether (other than changing the int name to something like x)?

The code currently looks something like this:

else if ((compoundedseriesofwords == yy || compoundedseriesofwords == zz || compoundedseriesofwords == aa || compoundedseriesofwords == bb || compoundedseriesofwords == cc) && compoundedseriesofwords == dd)

Like, can you do something like: compoundedseriesofwords == yy, zz, aa && compoundedseriesofwords == bb?

0

Nope. But you might consider a shorter variable name, like cmpd_wrds. Sometimes, you just have to put a long chain of tests in. Unless, of course, you can find a way to simplify the logic.

When this happens, my personal preference it to align matching phrases from one line to the next, but that usually doesn't make style50 happy. You need to learn the rules before you learn when it's ok to break them. ;-)

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .