comparing large arrays

So.. I have 2 codes, The intent is to descramble 10 words that are entered through cout / cin prompt. by savething them into 2 arrays, one consisting of the actual word, the other the words total ascii value. i am then attempting to compare the words i want to descramble to a "wordlist.txt" that i also have 2 arrays set up for one with the acutal word from the "wordlist.txt" and the other with all of the "wordlist.txt" ascii values. i then am trying to compare the ascii values to see if their equal and if so add them to my finalAnswerArray.

This first program goes as far as setting up all of my arrays succesfully (as far as i know) and prints out the results of the arrays. The issues you will see arises in my second code which is not comparing correctly, and getting stuck somewhere. Any input or help would be appreciated!

First Code- Currently Working

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
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int counter = 0;
int number = 0;
string asciiSum;
int sumUpdate = 0;
string getwordsArray[9];

void convertToASCII(string letter)
{
    int sum = 0;
    for (int i = 0; i < letter.length(); i++)
    {
        char x = letter.at(i);
        //cout << int(x) << endl;
        sum += int(x);
    }
    sumUpdate = sum;
}


string temp;
void getwords()
{

    for (int g = 0; g < 10; g++)
    {
        cout << "Please enter you word here " << g << ":\n";
        cin >> temp;
        getwordsArray[g] = temp;
    }
}

int main ()
    {
    getwords();

    int asciiArray[1275];
    string array[1275]; // creates array to hold names
    short loop=0; //short for loop for input
    string line; //this will contain the data read from the file
    ifstream myfile ("C:\\Users\\Zack\\Desktop\\wordlist.txt"); //opening the file.
    if (myfile.is_open()) //if the file is open
    {
    while (! myfile.eof() ) //while the end of file is NOT reached
    {
    getline (myfile,line); //get one line from the file
    array[loop] = line;
    cout << array[loop] << endl; //and output it
    asciiSum = line;
    convertToASCII(asciiSum);
    asciiArray[loop] = sumUpdate;
    cout << asciiArray[loop] << "\n" << "\n";
    loop++;
    }
    //cout << "the loop counted too: " << loop;

    myfile.close(); //closing the file
    string temp1;
    int getwordAsciiArray[9];
    for (int i = 0; i < 10; i++)
    {
        temp1 = getwordsArray[i];
        convertToASCII(temp1);
        getwordAsciiArray[i] = sumUpdate;
    }
    cout << "\nThis is the words array: \n";
    for (int i = 0; i < 10; i++)
    {
        cout << getwordsArray[i] << "\n";
    }
    cout << "\nThis is the value of each word in the array: \n";
    for (int i = 0; i < 10; i++)
    {
        cout << getwordAsciiArray[i] << "\n";
    }
    }
    else cout << "Unable to open file"; //if the file is not open output
    system("PAUSE");

}


Second set of Code:
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int counter = 0;
int number = 0;
string asciiSum;
int sumUpdate = 0;
string getwordsArray[9];
string primaryAnswerArray[9];
string primaryAnswer;
// small helper method to display the before and after arrays
void displayArray (string array[], int size)
{
 cout << "{";
 for ( int i = 0; i < size; i++ )
 {
  // you'll see this pattern a lot for nicely formatting
  // lists--check if we're past the first element, and
  // if so, append a comma
  if ( i != 0 )
  {
   cout << ", ";
  }
  cout << array[ i ];
 }
 cout << "}";
}

void convertToASCII(string letter)
{
    int sum = 0;
    for (int i = 0; i < letter.length(); i++)
    {
        char x = letter.at(i);
        //cout << int(x) << endl;
        sum += int(x);
    }
    sumUpdate = sum;
}



void getwords()
{
    string temp;
    for (int g = 0; g < 10; g++)
    {
        cout << "Please enter you word here " << g << ":\n";
        cin >> temp;
        getwordsArray[g] = temp;
    }
}

int main ()
    {
    getwords();
    int asciiArray[1275];
    string wordlistArray[1275]; // creates array to hold names
    short loop=0; //short for loop for input
    string line; //this will contain the data read from the file
    ifstream myfile ("C:\\Users\\Zack\\Desktop\\wordlist.txt"); //opening the file.
    if (myfile.is_open()) //if the file is open
    {
    while (! myfile.eof() ) //while the end of file is NOT reached
    {
    getline (myfile,line); //get one line from the file
    wordlistArray[loop] = line;
    //cout << wordlistArray[loop] << endl; //and output it
    asciiSum = line;
    convertToASCII(asciiSum);
    asciiArray[loop] = sumUpdate;
    //cout << asciiArray[loop] << "\n" << "\n";
    loop++;
    }
    }
    myfile.close(); //closing the file
    //cout << "the loop counted too: " << loop;
    getwords();

    string temp1;
    int getwordAsciiArray[19];
    for (int i = 0; i < 10; i++)
    {
        temp1 = getwordsArray[i];
        convertToASCII(temp1);
        getwordAsciiArray[i] = sumUpdate;
    }
//    cout << "\nThis is the words array: \n";
//    for (int i = 0; i < 10; i++)
//    {
//        cout << getwordsArray[i] << "\n";
//    }
//    cout << "\nThis is the value of each word in the array: \n";
//    for (int i = 0; i < 10; i++)
//    {
//        cout << getwordAsciiArray[i] << "\n";
//    }
    int a = 0;
    int b = 0;
    int d = 0;
    int e = 0;
    string secondaryAnswer;
    string secondaryAnswerArray[30];
    while(b < 1276)
    {
        while (b < 1275) /// While statement that gets all the words that match the entered word  ///
        {
        if (getwordAsciiArray[d] == asciiArray[b])
           {
            secondaryAnswer = wordlistArray[b];
            secondaryAnswerArray[a] = secondaryAnswer;
            a++;
           }
        b++;
        }
        b = 0;
      //  string primaryAnswer;
     //   string primaryAnswerArray[10];
        while (d < 10)  /// While statement that checks to see if the entered word matches wordlist.txt
        {
            for (int i = 0; i < a; i++)
            {
                if (secondaryAnswerArray[i] == getwordsArray[d])
                {
                    primaryAnswer = secondaryAnswerArray[i];
                    primaryAnswerArray[e] = primaryAnswer;
                    e++;
                    return 0;
                }
            }
        }
        d++;
        a = 0;
    }
    cout << "The words you entered are: \n";
    displayArray(getwordsArray, 10);
    cout << "The Final Answers are: \n";
    displayArray(primaryAnswerArray, 9);  /// Final Results
//    cout << "\nThis is the words array: \n";
//    for (int i = 0; i < 10; i++)
//    {
//        cout << getwordsArray[i] << "\n";
//    }
    //cout << "\nThis is the value of each word in the array: \n";
//    int b = 0;
//    int a = 0;
//    string finalAnswer;
//    string finalAnswerArray[9];
//   while (b < 1275)
//    {
//            if (getwordAsciiArray[a] == asciiArray[b])
//            {
//                finalAnswer = array[b];
//                finalAnswerArray[a] = finalAnswer;
//                a++;
//                b = 0;
//            }
//            b++;
//    }  // while statement
//    cout << "The Correct words are: \n";
//    for (int i = 0; i < 10; i++)
//    {
//        cout << finalAnswerArray[i] << "\n";
//    }
  //  }  // for if statement
}
Registered users can post here. Sign in or register to post.