帮我看下我的代码的错误

piaomiao163 2009-02-23 12:39:42
我想实现这样的功能:


我的代码:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
cout << "Please Enter Some IntNumbers" << endl;
vector<int> vector_int;
int i, j(0) ;
while( cin >> i )
{
vector_int.push_back( i );
++ j ;
}
if ( isdigit( j % 2 == 0 ) )
{
cout << "The number of Intnumbers is not enough" << endl;
}
else
{
for ( int i = 0; i < j; i+=2 )
cout << vector_int[ i ] + vector_int[ i+1 ] << endl;
}
system("pause");
}


运行的时候出现错误~~
...全文
360 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
HelloDan 2009-02-23
  • 打赏
  • 举报
回复

#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "Please Enter Some IntNumbers" << endl;
vector<int> vector_int;
int i;
while( cin >> i )
{
vector_int.push_back( i );
}

if ( vector_int.size()%2!=0 )
{
cout << "The number of Intnumbers is not enough" << endl;
}
else
{
for ( size_t i = 0; i < vector_int.size()-1; ++i )
cout << vector_int[ i ] + vector_int[ i+1 ] << endl;
}
system("pause");
}


//这样试一下吧。
waizqfor 2009-02-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 HelloDan 的回复:]
C/C++ code
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "Please Enter Some IntNumbers" << endl;
vector<int> vector_int;
int i;
while( cin >> i )
{
vector_int.push_back( i );
}

if ( vector_int.size()%2!=0 )
{
cout << "The number of Intnumbers is not enough" << endl;
} …
[/Quote]
UP
piaomiao163 2009-02-23
  • 打赏
  • 举报
回复
对对对·······我粗心了
bfhtian 2009-02-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 HelloDan 的回复:]
C/C++ code
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "Please Enter Some IntNumbers" << endl;
vector<int> vector_int;
int i;
while( cin >> i )
{
vector_int.push_back( i );
}

if ( vector_int.size()%2!=0 )
{
cout << "The number of Intnumbers is not enough" << endl;
} …
[/Quote]
up
renyaoming 2009-02-23
  • 打赏
  • 举报
回复
UP
renyaoming 2009-02-23
  • 打赏
  • 举报
回复
isdigit( j % 2 == 0 )的用法肯定不对
a_rockboy 2009-02-23
  • 打赏
  • 举报
回复
isdigit( j % 2 == 0 )的用法肯定不对
使用
if ( j % 2 != 0 )
{
cout << "The number of Intnumbers is not enough" << endl;
}

输入数据时用ctrl+z作为结束条件。

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧