Determine if "a" is a power of "b"

I'm asked to prompt the user for 2 integers, a and b. Determine if a is some power of b and output that claim. I cannot find a way to set that condition up though. I thought of logs, but I don't understand their applications in C++


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 int main()
{
	int a = 0;
	int b = 0;
	do{
	
	cout << "Input 2 Integers, a and b respectively." << endl;
	cin >> a >> b;
	if (a < 0 || b < 0)
	{
		cout << " Invalid Input" << endl;
	}
	else 
		if (????)
		{
			cout << a << " is a power of " << b << endl;
		}
		else
		cout << " No Match Found." << endl;
	} while( a < 0|| b < 0);
}
closed account (48T7M4Gy)
Maybe think about this:

1. a is a power of b
2. So, b*b* ... = a
3. If you start with 1 and keep multiplying by b and you go past a then a isn't a power of b
Last edited on
I thought so, but I had a hard time believing this was the "right" way. I expected something more convenient.
Thanks !
Topic archived. No new replies allowed.