I've been trying to solve this for an hour now and it is very frustrating, I cannot understand why the next loop just doesn't verify itself
while(p>1) {
p--;
if (pow(n, contor) == p) {
contor2++;
}
}
the full code being
#include <iostream>
#include <cmath>
int main()
{
int n, p, resetP;
float contor = 0;
float contor2 = 0;
n = 3;
p = 100;
resetP = p;
while (p > 1)
{
contor++;
p = p / n;
}
p = resetP;
while (p > 1)
{
p--;
if (pow(n, contor) == p)
contor2++;
}
std::cout << contor2;
}
what I am trying to do here is verify if(pow(3, 4)==81
but it just doesn't seem to work. The p
I set it from 100 to go one by one towards 0. When it gets to 81, it simply gets past over it, like it just doesn't verify the if
and my contor2
stays the exact same (that being 0). I've been studying C++ for over 6 months now, but this is the first time I'm really stuck on something.