Question: #include using namespace std; int count_digit_occurrences(int number, int digit){ int c = 0; while (number > 0){ int r = number % 10; number =

#include

using namespace std;

int count_digit_occurrences(int number, int digit){ int c = 0; while (number > 0){ int r = number % 10; number = (number - r) / 10; if(r == digit ){ c = c + 1; } } return c; } bool has_repeated_digits(int number){ int digit; for (digit = 0; digit < 10; digit++){ if(count_digit_occurrences(number, digit) > 1){ cout << "1"; return true; } else { cout << count_digit_occurrences(number, digit); return false; } } }

int main (){ cout << has_repeated_digits(335); return 0; }

Im trying to get has_repeated_digits() to show true if a number has repeating digits but but I keep getting 0 as the output and giving me false. I dont know whats wrong

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!