还是求输出一个数是几位数的题 怎么出现这种情况???

来源:百度知道 编辑:UC知道 时间:2024/08/21 20:09:23
在我运行的时候 在出结果的时候出现了一个警告对话框
Debug Error!
program:...\r400\Documents\Visual Studio
2008\Projects\sfa\Debug\sfa.exe
Module:....\r400\Documents\Visual Studio
2008\Projects\sfa\Debug\sfa.exe
File:
Run-Rime Check Failure #3-The variable 'n'is being used
without being initialized.
(Press Tetry debug the application)
源代码是:#include<iostream>
using namespace std;
void main()
{
int a,b,n;
cout<<"输入任意数:";
cin>>a;
while(n>0)
{
a=a/10;
b++;
}
cout<<"此数是"<<b<<"位数"<<endl;
}
大家帮我看看这段代码还有错误码
我用的是VASTA BUSINESS系统 由于不支持VC6.0所以安装了2008,是不是和编译环境有关啊!!还是就是代码有问题~~
不好意思 找到为什么啦 这么明显没发现 晕~~~~~~~~

while(n>0)
应为while(a>0),因为你是判断a为几位数。

int a,b,n;
这里b没有初始化
改为
int a,b=0;
就好了
:#include<iostream>
using namespace std;
void main()
{
int a,b=0;
cout<<"输入任意数:";
cin>>a;
while(a>0)
{
a=a/10;
b++;
}
cout<<"此数是"<<b<<"位数"<<endl;
}

你这也没定义n 和b,运行肯定没结果