Need help shifting array 2 spaces to the left.

My code is set up so that a user enters however big they need an array to be and can then choose from characters letters or special symbols. It then takes that input and tells you what each and everything you enter is. For example if you enter AsDf12@# It will say A is a cap s is a lower D is a cap 1 is a digit @ is a special and so on. It then Will reverse the input and change all capitals to lower case so the example above would be #@21FdSa. And Lastly I am supposed to shift all elements of the array 2 spaces to the left. Ie 54321 would become 32154. I have no idea how to shift an array. Any help would be greatly appreciated
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
 #include <iostream>

using namespace std;

int main()
{
    int N;          // This will be the number the user enters for size of array
    char choice;        // Choice on if they wish to select another array
    cout << "This is an array manipulation program" << endl;
    cout << "\nEnter the size of the array ";
    cin  >> N;
    char array[N];  // This is the array that will store all the inputs
    do
    {
    cout << "\nEnter any " << N << " Characters, Digits, or Special Symbols : ";
    for(int i=0; i <N; ++i)
    {
    cin>>array[i];
    }
    cout << "\n\nThe array contains the following   :   ";

    for(int i=0; i<N; i++)
    {
        cout<<array[i];
    }
    cout << endl;
    bool CapitalExists=false;       // this checks if Capital Letters Exist
    bool lowerExists=false;         // This checks if small letters exist
    bool digit=false;               // This checks if the input is a digit
    bool special=false;             // This checks if the input is a special symbol
    for(int i=0; i<N; i++)
    {
       if (array[i]>= 'A' && array[i]<= 'Z')
         {
             CapitalExists=true;
             cout << array[i] << "  is a Capital Letter" <<endl;

         }
         else if(array[i]>='a' && array[i]<='z')
         {
             lowerExists=true;
             cout << array[i] << "  is a Small Letter" <<endl;
         }
         else if(array[i]>=48 && array[i]<=57)
         {
             digit=true;
             cout << array[i] << "  is a Digit" <<endl;
         }
         else
         {
             special=true;
             cout << array[i] << "  is a Special Symbol" <<endl;
         }
    }
    if(!CapitalExists)
      cout<<"\n\nThere are no capital letters in the array \n" <<endl;
    if(!lowerExists)
      cout<<"\n\nThere are no small letters in the array \n" <<endl;
    if(!digit)
      cout<<"\n\nThere are no digits in the array \n" <<endl;
    if(!special)
      cout<<"\n\nThere are no Special Symbols in the array \n" <<endl;

     cout << "\n\n\nThe array in reverse order  ";

    for(int i=N-1; i>=0;i--)
    {
        cout<<array[i];
    }
    cout << "\n\nThe array after converting Capital Letters \nto Small Letters"
         << " and Vice Versa  : ";
    for(int i=N-1; i>=0;i--)
    {
        if(array[i]>='A' && array[i]<='Z')
            cout<<char(array[i]+=32);
        else if(array[i]>='a' && array[i]<='z')
            cout<<char(array[i]-=32);
        else cout <<array[i];
    }
    cout << "\n\nWould you like to check for another array?"
         << "\nEnter Y or y for Yes \nOR\nN or n for No -------> ";
    cin  >> choice;

    while (choice != 'y' && choice != 'Y' && choice != 'N' && choice != 'n')
        {
      cout << "Invalid Character, Enter Y, or y, or N, or n"
           << " ----->  ";
      cin  >> choice;

        }
    }
    while (choice != 'n' && choice != 'N');

    cout << "\n\nProgram is terminated" << endl;
    cout << "\nThis Algorithm Designed and Implemented by\n"
         << "Bob Dylan - Analysis Data Group\nOctober 30 - 2015" <<endl;

    return 0;
}

You copy it.

Arrayname[10] = {0,1,2,3,4,5,6,7,8,9)

okay now,

1 becomes 0
2 becomes 1
3 becomes 2
...
and 0 becomes 9

But How can i do that if the user can enter any number?

They enter the size of the array at array[N]
I could declare arrayname[10] and they could just enter arrayname[11]
I need it so that whatever they enter shifts 2 to the left. Or is what you just said exactly what im supposed to do hahah

That's the problems you face as a programmer. I used 10 because it was a short example.

You would start with N

string temp=array[0];
for (int i=0 to N-1){
array[i]=array[i+1];
}
array[N]=temp;
repeat
Last edited on
It said invalid conversion from char to constant char. Is it Because I declared N as an integer?
Topic archived. No new replies allowed.