c++ - Error when running code -
i have tried following code error when running it. have used debugger can't understand errors in call stack.
#include <iostream> #include <fstream> using namespace std; int main() { int a[10][2],i,j, b[10],max, min; ifstream f("numere.txt"); for(i=1;i<=10;i++) { for(j=1;j<=2;j++) { f>>a[i][j]; b[i]=0; } } for(i=1;i<=10;i++) { for(j=1;j<=2;j++) { b[i]=b[i]+a[i][j]; } } max=b[1]; min=b[1]; for(i=1;i<=5;i++) { if(max<=b[i]) max=b[i]; if(min>=b[i]) min=b[i]; } cout<<"cea mai mare suma este:"<< max<<endl; cout<<"cea mai mica suma este:"<< min<<endl; f.close(); return 0; }
please, me. beginner , have never worked files before.
you have @ least 1 error: array index out of bounds:
for(i= 0;i<10;i++) { //^^^ for(j=0;j< 2;j++) { //^^^ f>>a[i][j]; b[i]=0; //why put b[i] here?? } }
since declare a[10][2]
, array indices start 0
, not 1
in c++. access memory not belong a
(and b
).
Comments
Post a Comment