2

这段代码运行良好,但我得到一个没有输出的黑屏当我删除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;
}
4

2 回答 2

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;
}
于 2013-04-30T15:10:45.587 回答
0

如果您在第一个 for 循环中谈论 cin>>,那么 cin>> 用于从控制台获取 inpur。你应该给它一个输入,按回车。然后你的数组将被初始化。我认为您不欣赏 cin>> 的整个工作。

于 2013-04-30T15:42:31.510 回答