How do you check for a digit in a number?

Well I'm completely new to programming and all but I'm stuck on this last part of my program. I can't seem to understand how I would get it to check this rule. If a number is divisible by 5 and does not contain a 6 in it "Output: Bizz". Below is the farther I could think of but I have nooo idea why it won't pick it up. Please help and thanks for any input!

 
  if (((i % 5 != 0) && (i / 100 != 6)) || ((i % 5 != 0) && (i / 10 % 10 != 6)) || ((i % 5 != 0) && (i % 10 != 6)))
Rather than creating massive confusing if statements, try rewriting it as a collection of statements:
1
2
3
4
5
6
7
8
9
10
11
bool test(int x) {
    if (x % 5 != 0)
        return false; // not divisible by 5
    // ... test if each digit is a 6. If so, return true, otherwise:
    return false;
}

// ...

if (test(160))
    std::cout << "Bizz\n";

I'll leave it to you to do the calcs for each digit. As a hint, try using a loop to go through every digit in the number.
Alternatively you can convert your number to a string and check for a char '6'
Topic archived. No new replies allowed.