注册 登录
编程论坛 C++教室

求助!!!大家来看看为什么?

dxd000 发布于 2008-10-22 16:32, 496 次点击
我弄的通过键盘输入数字,然后显示出其中有多少个负数

#include <iostream>

main()

{
      int amount = 0, val;
      
      while (std::cin >> val)
      
           if (val < 0)
              
              ++amount;
              
      std::cout << << " the amout is : " << amount << std::endl;
     
      system("PAUSE");
      
      return 0;

}

但是输入数据以后不显示结果啊
5 回复
#2
zxwangyun2008-10-22 16:58
std::cout << << " the amout is : " << amount << std::endl;
这句cout后面的“<<”删除一个即可
#3
blueboy820062008-10-22 18:19
回复 1# dxd000 的帖子
编译器应该报错嘀~
#4
Soul寂2008-10-22 20:10
#include <iostream>

main()

{
      int amount = 0, val;
      
      while (std::cin>>val)
      
           if (val<0)
           {
              ++amount;
              
      std::cout <<" the amout is : "<< amount<<std::endl;
           }
     /* else
          std::cout <<" NO amout"<<std::endl;*/

      system("PAUSE");
      
      return 0;

}

你那代码的空格太多了!
#5
keanbin2008-10-22 21:42
我把你的改了一下:
#include <iostream.h>

void main()

{
      int amount = 0, val;
      
      
      do{
          cin >> val;
          if (val < 0)
          {
              ++amount;
          }          
      }while (val!=0);      
      cout<< " the amout is : " << amount << endl;
         


}
#6
keanbin2008-10-22 21:45
while (std::cin>>val){}  中用这个为条件的话变成了死循环,一直是输入数的状态!!
1