【发布时间】:2013-07-28 08:40:59
【问题描述】:
我只想让用户输入一些数字。如果数字为 -1,则程序停止,然后输出相同的数字。为什么这么难?我不明白为什么这里的逻辑不起作用。
例如当用户输入:
1 2 3 -1
然后程序应该打印出: 1 2 3 -1
#include <iostream>
using namespace std;
int main()
{
int input, index=0;
int array[200];
do
{
cin >> input;
array[index++]=input;
} while(input>0);
for(int i=0; i < index; i++)
{
cout << array[index] << endl;
}
}
【问题讨论】:
-
问题是什么? p.s.您应该在
main()末尾添加一个return 0 -
什么不符合您的预期?
-
当我输入 1 2 3 -1 时。我没有找回那些数字。
标签: c++