Exceeding array boundary

So my lab instructor told me I can rotate my function in a clockwise fashion by using modular within the array (see last 6 lines), thereby helping me move the entire array's elements depending on how much the user wants to rotate.
When I tried it didn't work, can it really do that though?

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <iomanip>
using namespace std;

void turn(int [], int &);

void main()
{
	int numbers [10];
	int turns;
	char k;
	bool done;

	done=false;

	cout<<"Enter 10 numbers: ";
	for (int i=0;i<10;i++)
	{
		cin>>numbers [i];
	}

	cout<<"Enter the number of turns that will be made (value must be positive)";
	cout<<"\n";
	cout<<"x= ";

	while (!done)
	{
		cin>>turns;
		if (turns<0)
		{
			done=false;
		}
		else
		{
			done=true;
		}
	}

	cout<<"\n";
	turn (numbers, turns);
	cout<<"\n";
	
	cout<<"Enter any character to continue...";
	cout<<"\n";
	cin>>k;
}

void turn(int numbers[], int &turns)
{
	int backup[10];
	int j;
	char k;

	if (turns==0)
	{
		cout<<"Number arrangement will remain the same.";
		cout<<"\n";
		cout<<"Enter any character to exit...";
		cout<<"\n";
		cin>>k;
		exit (1);
	}

	for (int k=0;k<10;k++)
	{
		backup[k]=numbers[(k-turns)%10];             //Turns is x
		cout<<backup[k]<<" ";
	}
}
Suppose k is 3 and n is 6.
So the 1st array element should have 4th array element after turning.
i.e backup[0] = numbers[4];
But for boundary cases we use modular operation.
i.e backup[k] = numbers[(k+turns)%10];
Topic archived. No new replies allowed.