Deque not storing properly

Hello. I have a Deque which I am trying to use to store a certain position for a letter in a sentence. The code is as follows:

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include "string.h"
#include <fstream>
#include "conio.h"
#include <vector>
#include <deque>

using namespace std;

int main()
{

    char iword[200];
    string iword2, astring;
    int ilength=0, acount=0, ecount=0, icount=0, jcount=0, dcount=0;





    cout<<"Write a word to encrypt: ";
    cin.get(iword, sizeof(iword)); cin.ignore(1000, '\n');
    iword2=iword;
    ilength=iword2.length();




for(int i=0; i<ilength; i++){
    if(iword[i]=='A'){
    iword[i]='H';}

    else if(iword[i]=='B'){
    iword[i]='i';}

    else if(iword[i]=='C'){
    iword[i]='N';}

    else if(iword[i]=='D'){
    iword[i]='T';}

    else if(iword[i]=='E'){
    iword[i]='p';}

    else if(iword[i]=='F'){
    iword[i]='f';}

    else if(iword[i]=='G'){
    iword[i]='P';}

    else if(iword[i]=='H'){
    iword[i]='e';}

    else if(iword[i]=='I'){
    iword[i]='v';}

    else if(iword[i]=='J'){
    iword[i]='A';}

    else if(iword[i]=='K'){
    iword[i]='S';}

    else if(iword[i]=='L'){
    iword[i]='F';}

    else if(iword[i]=='M'){
    iword[i]='q';}

    else if(iword[i]=='N'){
    iword[i]='l';}

    else if(iword[i]=='O'){
    iword[i]='t';}

    else if(iword[i]=='P'){
    iword[i]='D';}

    else if(iword[i]=='Q'){
    iword[i]='g';}

    else if(iword[i]=='R'){
    iword[i]='f';}

    else if(iword[i]=='S'){
    iword[i]='e';}

    else if(iword[i]=='T'){
    iword[i]='B';}

    else if(iword[i]=='U'){
    iword[i]='j';}

    else if(iword[i]=='V'){  //bcdehkmnrsu EGIJKLMOQRUV
    iword[i]='C';}

    else if(iword[i]=='X'){
    iword[i]='o';}

    else if(iword[i]=='Y'){
    iword[i]='a';}

    else if(iword[i]=='Z'){
    iword[i]='f';}





}
cout<<"\n\nTest: "<<iword;

deque<int>a_deque(ilength);
    for(int i=0; i<ilength; i++){
            if(iword[i]=='H'){
    acount++;
    a_deque.push_front(i);}
    cout<<i<<endl;
    }

 for(int i=0; i<a_deque.size(); i++){
        try{cout<<"\nPlace: "<<i<<" Number: "<<a_deque.at(i)<<endl;}
        catch(exception& e){cout<<"\nElement "<<i<<" exceeds deck dimensions.";}

    }
    cout<<iword;

















    return 0;
}


However even how hard I try the deque remains empty. I don't know what to do really..I am puzzled.
The why that you have it coded, it will only store a new value other than zero is if the encrypted string has a 'H' and only way to get a 'H' is to have a 'A' in the encrypting string. Now if 'A' is the first char in the string the deque will store the value 0 which looks no different than the other 0 values created by the deque<int>a_deque(ilength); statement.
I got this using the input string "This is A test" notice that 'A' is not at the beginning and 8 shows up in the output at the first position as coded using the a_deque.push_front(i);
$ ./a.out
Write a word to encrypt: This is A test

Test: Bhis is H test
0
1
2
3
4
5
6
7
Pushing(8)
8
9
10
11
12
13
Place: 0 Number: 8  <--- Place is 0 in the deque and 8 is the position in the input string.
Place: 1 Number: 0
Place: 2 Number: 0
Place: 3 Number: 0
Place: 4 Number: 0
Place: 5 Number: 0
Place: 6 Number: 0
Place: 7 Number: 0
Place: 8 Number: 0
Place: 9 Number: 0
Place: 10 Number: 0
Place: 11 Number: 0
Place: 12 Number: 0
Place: 13 Number: 0
Place: 14 Number: 0

It is doing what you coded it to do.
Last edited on
Topic archived. No new replies allowed.