鱼C论坛

 找回密码
 立即注册
查看: 3813|回复: 2

编译完全成功(没有报错和警告)但运行异常

[复制链接]
发表于 2013-5-12 09:44:30 | 显示全部楼层 |阅读模式
3鱼币
本帖最后由 dt3tc 于 2013-5-12 09:51 编辑

Enter a small number: 2
Enter a large number: 10000
small: 2...
程序运行到一半就卡住了
请问为什么不能运行21行的while语句
  1. #include <iostream>

  2. using std::cin;
  3. using std::cout;
  4. using std::endl;
  5. int main()
  6. {
  7.         unsigned short small;//初始化变量
  8.         unsigned long large;//初始化变量

  9.         const unsigned short MAXSMALL=65535;//定义常量

  10.         cout<<"Enter a small number: ";//打印
  11.         cin>>small;

  12.         cout<<"Enter a large number: ";//打印
  13.         cin>>large;

  14.         cout<<"small: "<<small<<"...";//打印

  15.         while ((small<large)&&(small<MAXSMALL))//假设
  16.         {
  17.                         if(small%5000==0)//假设
  18.                         {
  19.                                 cout<<".";
  20.                                 small++;
  21.                                 large-=2;
  22.                         }
  23.         }
  24.         cout<<"\nSmall: "<<small<<",large:"<<large<<endl;//打印
  25.         cout<<endl<<"press enter to continue";//输出提示
  26.         cin.clear();
  27.         cin.sync();
  28.         cin.get();
  29.         return 0;
  30. }
复制代码



最佳答案

小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-5-12 09:44:31 | 显示全部楼层
        while ((small<large)&&(small<MAXSMALL))//假设
        {
                        if(small%5000==0)//假设
                        {
                                cout<<".";
                                small++;
                                large-=2;
                        }
        }
这句是运行了的,只是死循环了。按照你的输入
small%5000这个的值是等于2的。
然后就一直在while里面循环
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-5-12 13:50:14 | 显示全部楼层
楼上牛人啊。。。膜拜。。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-28 14:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表