Hi I have a algorithm I am trying to create but I cant seem to make it work?
This is what i have to do:
Describe an algorithm that takes integer n and digit d as the parameters, and computes the number of
occurrences of d in the decimal expansion of n.
For instance, if n = 65454871 and d = 4, then the algorithm should return 2.
Implement the corresponding function and test it
And here is my code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int co; // variable count occurences AKA co
int n, d;
int rem; // variable remainder
cout << "Enter a decimal number: ";
cin >> n;
cout << "Enter a diget to find: ";
cin >> d;
cout << "n= "<< n << " d= "<< d << endl;
while (n > 0) {
rem = n % 10;
n = n / 10;
if (rem = d) {
co++;
}
}
return co;
return 0;
}// end of main