c++ - 获取矩阵错误 cin>>

标签 c++ visual-c++

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

最佳答案

#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;
}

关于c++ - 获取矩阵错误 cin>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16302762/

相关文章:

visual-c++ - 如何防止此 CMFCPropertySheet 的高度调整得太小?

c++ - 在类内部和外部定义的模板类的成员函数之间的区别

c++ - 一些浮点精度和数值限制问题

c++ - 如何在项目中只包含 BOOST 智能指针代码?

C++ 修饰 basic_stream::underflow()

c++ - 用于多态性的引用和指针?

c++ - 这是 VC++ 2010 中的错误吗?

c++ - 如何将字符数组转换为字符串?

.net - 在托管 C++ 中创建 KeyValuePair

c++ - WriteFile 函数返回成功但无法查看文件系统中的文件