I'm currently in an extremely basic C++ class and we are writing a program to check if an input is a string or has digits within it. I currently have my code and everything seems to be in order however, when I attempt to test it I get the error:
Line should be less than or equal to 80 characters long.
The error location reveals this as the problem:
if ((checknum == 1 && checkVector[0] == 1)|| checknum == 0 || checknum == strlength) {
Is there any way to break this up into multiple lines to avoid this error? It will not let me run it without all of the white spaces.
You can put line breaks anywhere that whitespace is allowed:
if ((checknum == 1 && checkVector[0] == 1)||
checknum == 0 ||
checknum == strlength) {
Or you could set variables:
int check1 = checknum == 1 && checkVector[0] == 1;
int check2 = checknum == 0;
int check3 = checknum == strlength;
if (check1 || check2 || check3) {
This isn't exactly equivalent, because || performs short-circuiting, and doesn't bother evaluating later operands if an earlier operand is true. But since there are no side effects or expensive calculations in your expressions, the difference is negligible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With