Program wont run

Can someone tell me why this wont run correctly?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;
int main()
{
 const int arraySize = 25;
 const int patternSize = 10;

 int *arr1;

 arr1 = new int[arraySize];

 arr1[arraySize] = {0,1,2,3,4,5,6,7,8,9};

 for(int i=0; i<arraySize; i++)
 {	 
	 cout << arr1[i%patternSize] << " ";

 }
	

	system("PAUSE");
	return 0;
}
It's working as intended. Trust me
I keep getting error messages though
Lol, I'm just messing with you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
int main()
{
 const int arraySize = 25;
 const int patternSize = 10;

 

 int arr1[arraySize] = {0,1,2,3,4,5,6,7,8,9};

 for(int i=0; i<arraySize; i++)
 {	 
	 cout << arr1[i%patternSize] << " ";

 }
	

	system("PAUSE");
	return 0;
}


use this.

I have zero clue why you're using that new operator.
Last edited on
@OP
Line 13. You are accessing the array at an index beyond its boundaries. Then, (this is where the compiler error comes in) you attempt to assign an entire initializer list to an int.

Edit:
If you use new, remember to use delete.
Last edited on
I am suppose to use a dynamic array though
After creating the array, you can use a for loop to assign numbers 0 to 9.

Oh, and I would like to point out that your for loop on line 15 can be simplified. There is no need for modulo magic.
15
16
17
18
19
 for(int i=0; i<patternSize; i++)
 {	 
	 cout << arr1[i] << " ";

 }


And don't forget freeing your resources.
Topic archived. No new replies allowed.