+ 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; }
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;
}
+ 2
Do you have a variable naming conflict in function f?
+ 2
Just a moment