5 errors T_T

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include iostream
#include string
int d;
int o;
string your;


#include<iostream.h>

void main()
{
	string home;
        int i,j,m=10,n=10;
	int arr1[10][10],arr2[10][10];

	while(i<=m)
	{
		i=1;
		while(j<=n)
		{
		  arr1[i][j] = arr2[i][j];
		  j++;
		}
		i++;
	}
char work[10];
} 




can some1 fix it ?? thanks!
Hi, if you have arr1[10], then its actual elements are labeled arr1[0], ..., arr1[9]. In your code, you are calling arr1[10] which should crash your program, because arr1[10] it outside of the memory reserved by you.

Second, the i=1; should be i=0;: in c++ counting of indices is assumed to start from 0, not from 1.

Third, your i=1; is placed wrongly; it will cause your program to have an infinite cycle. Try to fix it on your own!

Cheers!
Last edited on
I made some notes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream> // use angle brackets
#include <string> // use angle brackets
int d;
int o;
std::string your; // prefix with std:: from standard libs


// #include<iostream.h> // Don't use this its old

int main() // main MUST be int, NOT void
{
	std::string home; // prefic with std::
        int i,j,m=10,n=10;
	int arr1[10][10],arr2[10][10];

	i = 0; // initialise i

//	while(i<=m) // this will go too far
	while(i < m) // This will stay in bounds
	{
		//i=1; // Why this? Your loop will never end.

//		while(j<=n) // Out of bounds again
		while(j < n)
		{
		  arr1[i][j] = arr2[i][j];
		  j++;
		}
		i++;
	}
char work[10];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include iostream
#include string
int d;                                                    //    d
int o;                                                   //     o
string your;                                  //     your


#include<iostream.h>

void main()
{
	string home;                              //home
        int i,j,m=10,n=10;
	int arr1[10][10],arr2[10][10];

	while(i<=m)
	{
		i=1;
		while(j<=n)
		{
		  arr1[i][j] = arr2[i][j];
		  j++;
		}
		i++;
	}
char work[10];                      //work
} 


do your home work bro!!!
Topic archived. No new replies allowed.