I have tried blanking out a character after it is checked so it is not checked for again but the program just crashes,
I have also tried swapping the used element with the first and then ignoring the first but it still just crashes.
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
void showBlanks(int num1, int num2, int num3, int num4);
void numerate(char enterArray[][45])
{
////THIS IS FOR TEST PURPOSES ONLY. DELETE THIS EVENTUALLY.
//int count=0;
//int number=enterArray.size();
//for (int i=0;i<number;i++)
//{
// count++;
//
//}
//cout<<"\n"<<count;
//
//
//
//
}
bool searchDictionary(char dictionary[][45], char word[],int limit)
{
int low, mid, high; // array indices for search
low = 0;
high = limit - 1;
while ( low <= high) {
mid = (low + high) / 2;
// printRow( array, low, mid, high); // display to show progress
if ( strcmp(word,dictionary[ mid])==0)
{
// strcpy(dictionary[mid],"");
//dictionary[mid]=" ";
return true;
}
else if (strcmp(word,dictionary[ mid])<0)
high = mid - 1;
else
low = mid + 1;
}
return false;
}
bool noRepeats(char entered[7],int count)
{
int testCount;
char possible3 [27][4];
char possible4 [256][5];
char possible5 [3125][6];
char possible6 [46656][7];
if (strlen(entered)==3)
{
for (int i=0; i<27; i++)
{
strcpy(possible3[i],entered);
for (int j=count-1; j>=0; j--)
{
// cout<<"J is:"<<j<<" ^"<<possible3[j]<<"^ -> "<<"I is "<<i<<" "<<possible3[i]<<endl;
if (strcmp(possible3[j],possible3[i])==0) return false;
}
}
}
if (strlen(entered)==4)
{
for (int i=0; i<256; i++)
{
strcpy(possible4[i],entered);
for (int j=count-1; j>=0; j--)
{
// cout<<"J is:"<<j<<" ^"<<possible4[j]<<"^ -> "<<"I is "<<i<<" "<<possible4[i]<<endl;
if (strcmp(possible4[j],possible4[i])==0) return false;
}
}
}
if (strlen(entered)==5)
{
for (int i=0; i<3125; i++)
{
strcpy(possible5[i],entered);
for (int j=count-1; j>=0; j--){
// cout<<"J is:"<<j<<" ^"<<possible5[j]<<"^ -> "<<"I is "<<i<<" "<<possible5[i]<<endl;
if (strcmp(possible5[j],possible5[i])==0) return false;
}
}
}
if (strlen(entered)==6)
{
for (int i=0; i<46656; i++)
{
strcpy(possible6[i],entered);
for (int j=i-1; j>=0; j--){
// cout<<"J is:"<<j<<" "<<"^"<<possible6[j]<<"^ -> "<<"I is "<<i<<" "<<possible6[i]<<endl;
if (strcmp(possible6[j],possible6[i])==0) return false;
}
}
}
for (int i=0;i<27;i++)
// {
// cout<<possible3[i]<<endl;
//testCount++; cout<<testCount<<endl;}
return true;
}
void twistWord(char scramble[7])
{
char tempArray[7]={scramble[0],scramble[1],scramble[2],scramble[3],scramble[4],scramble[5]};
srand(time(NULL));
rand();
int n1=0;
int n2=0;
int n3=0;
int n4=0;
int n5=0;
int n6=0;
n1=rand()%6+1;
do{n2=rand()%6+1;}while(n2==n1);
do{n3=rand()%6+1;}while(n3==n2||n3==n1);
do{n4=rand()%6+1;}while(n4==n3||n4==n2||n4==n1);
do{n5=rand()%6+1;}while(n5==n4||n5==n3||n5==n2||n5==n1);
do{n6=rand()%6+1;}while(n6==n5||n6==n4||n6==n3||n6==n2||n6==n1);
//}while (n1!=n2!=n3!=n4!=n5!=n6);
int randArray [7]={n1,n2,n3,n4,n5,n6};
for (int i=0;i<6;i++)
{
tempArray[i]=scramble[randArray[i]-1];
}
for (int i=0;i<6;i++)
cout<<tempArray[i];
}
void setWord(){}
void showWords(char wordToUse[],char dictionary[][45],char numLetters3[4],bool blanks)
{
// int arraySize=0;
// char cheater[arraySize][7];
int rowCount=-1;
int testCount=0;
int count3=0; int count4=0; int count5=0; int count6=0;
// int a=0; int b=0; int c=0; int d=0; int e=0; int f=0;
int slot=0;
// char tempWordArray[];
char letter1, letter2, letter3, letter4, letter5, letter6;
// string check;
// char blank='a';
//cycle through every 3 letter word possibility to find if it is a word
for (int x=0;x<6;x++)
{
// cout<<"hi";
letter1=wordToUse[x];
for (int a=0;a<6;a++)
{
letter2=wordToUse[a];
// char temp= wordToUse[0];
// wordToUse[0]=wordToUse[a];
// wordToUse[a]= temp;
for (int b=0;b<6;b++)
{
letter3=wordToUse[b];
// wordToUse[b]='-';
char checkWord3[4]={letter1,letter2,letter3};
if (searchDictionary(dictionary,checkWord3,7660)==true)
{
bool test1= noRepeats(checkWord3,count3);
count3++;
cout<<test1<<endl;
if (blanks==false/*&&test1==true*/)
cout<<checkWord3<<endl;
}
for (int c=0;c<6;c++)
{
letter4=wordToUse[c];
// wordToUse[c]='-';
char checkWord4[5]={letter1,letter2,letter3,letter4};
if (searchDictionary(dictionary,checkWord4,7660)==true)
{
bool test2= noRepeats(checkWord4,count4);
count4++;
cout<<test2<<endl;
if (blanks==false/*&&test2==true*/)
cout<<checkWord4<<endl;
}
for (int d=0;d<6;d++)
{
letter5=wordToUse[d];
// wordToUse[d]='-';
char checkWord5[6]={letter1,letter2,letter3,letter4,letter5};
if (searchDictionary(dictionary,checkWord5,7660)==true)
{
bool test3 = noRepeats(checkWord5,count5);
count5++;
cout<<test3<<endl;
if (blanks==false/*&&test3==true*/)
cout<<checkWord5<<endl;
}
for (int e=0;e<6;e++)
{
letter6=wordToUse[e];
// wordToUse[e]='-';
char checkWord6[7]={letter1,letter2,letter3,letter4,letter5,letter6};
if (searchDictionary(dictionary,checkWord6,7660)==true)
{
bool test4=noRepeats(checkWord6,count6);
count6++;
cout<<test4<<endl;
if (blanks==false/*&&test4==true*/)
cout<<checkWord6<<endl;
}
}
}
}
}
}
}
//for (int z=0; z<arraySize; z++)
// cheater[z]=
cout<<count3<<count4<<count5<<count6<<endl;
if (blanks==true)
showBlanks(count3,count4,count5,count6);
//e//lse
}
void showBlanks(int num1, int num2, int num3, int num4)
{
cout<<num1<<endl;
cout<<num2<<endl;
cout<<num3<<endl;
cout<<num4<<endl;
for (int a=0; a<num1; a++ ){
// cout<<num1<<endl;
if (a%3==0)
cout<<"\n"<<"___"<<" ";
else
cout<<"___"<<" ";
}
for (int b=0; b<num2; b++ ){
// cout<<num2<<endl;
if (b%3==0)
cout<<"\n"<<"____"<<" ";
else
cout<<"____"<<" ";
}
for (int c=0; c<num3; c++ ){
// cout<<num3<<endl;
if (c%3==0)
cout<<"\n"<<"_____"<<" ";
else
cout<<"_____"<<" ";
}
for (int d=0; d<num4; d++ ){
// cout<<num4<<endl;
if (d%3==0)
cout<<"\n"<<"______"<<" ";
else
cout<<"______"<<" ";
}
cout<<endl<<endl;
}
//void cheat(){}
void displayIntro()
{
cout<<" hello there"<<endl;
}
void static displayBoard(int letters3found, int letters4found, int letters5found, int letters6found,
char arrayFor3s[][4],char arrayFor4s[][5],char arrayFor5s[][6],char arrayFor6s[][7])
{
// for (int count =0; count < letters3found; count++)
// {
// strcpy(letters3[count],"___");
// if (count%3==0)
// cout<<"\n"<<letters3[count]<<" ";
// else
// cout<<letters3[count]<<" ";
// }
}
int main ()
{
char wordToUse[45];
bool blanks=true;
char entry;
int letsFound3=0;
char blank3[4]="___";
char blank4[5]="____";
char blank5[6]="_____";
char blank6[7]="______";
// letters3= new char[10];
// for (int count =0; count < dynamo; count++)
// {
// strcpy(letters3[count],blank3);
// if (count%3==0)
// cout<<"\n"<<letters3[count]<<" ";
// else
// cout<<letters3[count]<<" ";
// }
// ={"___"};
////for (int count=0;count<dynamo; count++)
// letters4= new char[10];
// // ={"____"};
// letters5= new char[10];
// // ={"_____"};
// letters6= new char[10];
// ={"______"};
displayIntro();
int letterCount;
char words[7660][45];
ifstream dictionary("dictionary.txt");
srand(time(NULL));
int n = 0;
while(dictionary >> words[n])
{
n++;
}
rand();
do{
int r = rand() % 7660;
//wordToUse= words[r];
strcpy(wordToUse,words[r]);
} while ((strlen(wordToUse))!=6);
cout<<wordToUse<<endl;
twistWord(wordToUse);
//system("pause");
//***********cout<< "word: " << wordToUse << "\n";
//Splitting the String into a char array
//char splitString[6];
//for (int i=0;i<=6;i++)
//{
// splitString[i]=output[i];
// cout<<splitString[i]<<endl;
//}
cout<<endl<<endl;
// displayBoard(w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13,w14,w15,w16,w17,w18,w19,w20,w21,w22,w23,w24,w25,w26);
showWords("trucks",words,blank3/*,letters4,letters5,letters6,*/,true);
cout<<"Possible commands are:"<<endl;
cout<<" x to exit the game"<<endl;
cout<<" t to twist the letters into a different order"<<endl;
cout<<" s to set the word to letters of your choosing"<<endl;
cout<<" c to cheat, displaying all words"<<endl<<endl;
cin>>entry;
if (entry =='x') /*closes the program*/;
else if (entry=='t') /*twistWord();*/;
else if (entry=='s') setWord();
else if (entry=='n') numerate(words);
else if (entry=='c')
{
showWords("trucks",words,blank3/*,letters4,letters5,letters6,*/,false);
cout<<"hi";
}
cout<<endl<<endl;
system("pause");
}

New Topic/Question
Reply



MultiQuote







|