这段代码效果很好,但是我得到一个没有输出的黑屏
当我删除cin>>
时效果很好,但没有cin>>
此程序无效。
#include <iostream>
using namespace std;
int main ()
{
int x [5];
int i;
int sum;
for(i = 0;i < 5;i++)
cin>>x[i];
for (i=0;i<5;i++)
cout<<x[i];
for (i=0;i<5;i++)
sum=sum+x[i];
cout<<sum ;
int z;
cin>>z;
return 0;
}
答案 0 :(得分:2)
#include <iostream>
using namespace std;
int main ()
{
int x [5]={};
int i;
int sum=0;
cout << "please enter five integers (seperated with spaces) and press return: ";
for(i = 0;i < 5;i++){
cin>>x[i];
}
cout << "the integers you entered are: ";
for (i=0;i<5;i++){
cout<<x[i]<<" ";
}
cout << endl;
cout << " the culmulative sums of those integers are: ";
for (i=0;i<5;i++){
sum=sum+x[i];
cout<<sum << endl;
}
int z;
cout << "enter another integer" << endl;
cin>>z;
cout << "ok i'm ending the program without doing anything with the last int you entered" << endl;
return 0;
}
答案 1 :(得分:0)
如果你在谈论cin&gt;&gt;在第一个for循环中,然后cin&gt;&gt;用于从控制台获取inpur。 你应该给它一个输入,按回车键。然后你的数组将被初始化。我想你并不欣赏cin&gt;&gt;的整个工作。