+ 2

I want to write a function that calculates the number of digits. What is the problem with this code?

I want to write a function that calculates the number of digits. What is the problem with this code? #include <iostream> using namespace std; int f(int x); int main() { int a; cin >> a; int b; b=f(a); cout<< b << endl; return 0; } int f(int x ) { int x; int count=0; // cin>>x; while(x>=1) { count++; x/=10; } return count; }

16th Apr 2022, 6:31 AM
Mhdis
Mhdis - avatar
4 Answers
+ 2
int f(int x); int main() { int a; cin >> a; int b; b=f(a); cout<< b << endl; return 0; } int f(int x ) { int x; // đŸ€”X IS ALREADY A PARAMETERđŸ€” int count=0; // cin>>x; while(x>=1) { count++; x/=10; } return count; }
16th Apr 2022, 6:49 AM
Oma Falk
Oma Falk - avatar
+ 2
Do you have a variable naming conflict in function f?
16th Apr 2022, 6:49 AM
Seb TheS
Seb TheS - avatar
+ 2
Just a moment
16th Apr 2022, 7:11 AM
Behzod
Behzod - avatar