What I want to happen here is whenever result[0]
(randomly generated letter) is found in array1
(list of words), the word should move to array2
.
But when I display array2
, I get the original words no matter what result[0]
is. And when I display found
I get a string of numbers repeated (~4942576). What am I doing wrong?
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <string>
using namespace std;
char response;
int letter;
int letter2;
int n;
char result[8];
size_t found= 0;
string array1[70549];
string array2[70549] ;
string array3[70549] ;
string array4[70549] ;
string array5[70549] ;
string array6[70549] ;
string array7[70549] ;
string array8[70549] ;
string array9[70549] ;
string array10[70549] ;
char test = 'a';
int j = 0;
int k = 0;
int main()
{
pointer:
for (int a =0; a<8; a++)
{
cout<< "Consonant (c) or vowel(v)?" << endl;
cin >> response;
{
if ( 'c' == response )
{
srand (time(0));
letter = (rand() %21);
n ++;
switch (letter) //selects random const
{
case 0:
cout << "b" << endl;
result[n] = 'b';
break;
case 1:
cout << "c" << endl;
result[n] = 'c';
break;
case 2:
cout << "d" << endl;
result[n] = 'd';
break;
case 3:
cout << "f" << endl;
result[n] = 'f';
break;
case 4:
cout << "g" << endl;
result[n] = 'g';
break;
case 5:
cout << "h"<< endl;
result[n] = 'h';
break;
case 6:
cout << "j" << endl;
result[n] = 'j';
break;
case 7:
cout << "k" << endl;
result[n] = 'k';
break;
case 8:
cout << "l" << endl;
result[n] = 'l';
break;
case 9:
cout << "m" << endl;
result[n] = 'm';
break;
case 10:
cout << "n" << endl;
result[n] = 'n';
break;
case 11:
cout << "p" << endl;
result[n] = 'p';
break;
case 12:
cout << "q" << endl;
result[n] = 'q';
break;
case 13:
cout << "r" << endl;
result[n] = 'r';
break;
case 14:
cout << "s"<< endl;
result[n] = 's';
break;
case 15:
cout << "t" << endl;
result[n] = 't';
break;
case 16:
cout << "v"<< endl;
result[n] = 'v';
break;
case 17:
cout << "w"<< endl;
result[n] = 'w';
break;
case 18:
cout << "x" <<endl;
result[n] = 'x';
break;
case 19:
cout << "y"<< endl;
result[n] = 'y';
break;
case 20:
cout << "z"<< endl;
result[n] = 'z';
break;
}
}
else if ('v' == response)
{
srand (time(0));
letter2 = ( rand() %4);
n++;
switch (letter2) //selects random vowel
{
case 0:
cout << "a"<< endl;
result[n] = 'a';
break;
case 1:
cout << "e" <<endl;
result[n] = 'e';
break;
case 2:
cout << "i"<< endl;
result[n] = 'i';
break;
case 3:
cout << "o"<< endl;
result[n] = 'o';
break;
case 4:
cout << "u" << endl;
result[n] = 'u';
}
}
else if ( response != 'c' || 'v')
{
cout << "Invalid, please choose 'c' or 'v'"<< endl;
cin >> response;
}
}
}
cout<<endl<< "Your letters are";
for(int i=0; i<8; i++)
{
cout << result[i];
cout << " ";
}
ifstream file("C:\\Users\\Chris\\Documents\\words.txt");
if(file.is_open())
{
for(int i = 0; i < 70549; ++i)
{
file >> array1[i];
}
}
for (int i =0; i < 70549; i ++)
{
std::size_t found = array1[i].find(result);
if (found!=std::string::npos)
cout << array1[i] << ' ';
}
cout << endl << endl<<"Your words are: ";
for (int i =0; i <sizeof(array2[i]); i++)
cout << array2[i] << endl;
return 0;
}