有大侠知道下面程序哪里出错了,这个c++程序编译时无错误无警告可运行时有错误是为什么啊???

#include <stdio.h>
void mian()
{
int num=18;
int ans;
int c=0;
printf("请猜一猜我的年龄是多少?\n");
do
{
scanf("%d",&ans);
if(num>ans)
printf("讨厌!人家有这么小吗?\n");
else if(num<ans)
printf("去死!把人家说得这么老!\n");
else
printf("你真厉害!难道你就是命中注定的另一半?!\n");
}
while(num!=ans);
if(c==1)
printf("s\n");
if(c>1 && c<3)
printf("A\n");
if(c>3 && c<6)
printf("B\n");
if(c>6)
printf("foolish!\n");
}

你好!

  主函数 main 写错了

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-09-22

修改完整如下 :

#include <stdio.h>
void main() //-----------mian
{
int num=18;
int ans;
int c=0;
printf("请猜一猜我的年龄是多少?\n");
do
{
scanf("%d",&ans);
if(num>ans)
printf("讨厌!人家有这么小吗?\n");
else if(num<ans)
printf("去死!把人家说得这么老!\n");
else
printf("你真厉害!难道你就是命中注定的另一半?!\n");
c++; //---------计数累加
} while(num!=ans);
if(c==1)
printf("s\n");
if(c>1 && c<3)
printf("A\n");
if(c>3 && c<6)
printf("B\n");
if(c>6)
printf("foolish!\n");
}

第2个回答  2014-09-22
你的main函数哪儿去了。

do循环里应该加一句++c;否则c一直为0,那么循环后的输出全都不执行。
第3个回答  2014-09-22
你检查别的原因吧,代码没有问题……不过c没有在do循环中赋值,所以if以后都不会执行。
相似回答