Question
Modify the C code to include at least 4 functions and insure the code still runs. #include #include int main (void) { int i, j,
Modify the C code to include at least 4 functions and insure the code still runs.
#include
int main (void) { int i, j, x, y, initCount=6, add = 0, count=0, k=0, r, n=12, ent=0, temp, rev, game[20][24]; char ch, str[100], initStr[6], comma, var; system("cls||clear"); printf("Welcome to the Word Search Puzzle! This program will allow you to create your own word search puzzle, then play it. "); printf("Press Enter key to get started! "); //printf("This program will allow you to create your own word search puzzle, then play it. "); scanf("%c", &ch); do { var = '0'; add = 0; printf(" "); for (i=0; i<=19; i++) for (j=0; j<=23; j++) { r=rand() %(90 - 65 +1) +65; game[i][j] = r; } switch(initCount) { case 6: system("cls||clear"); printf("Enter 6 words to create your puzzle. Please enter all UPPER CASE letters. Your words should be between 5 and 12 characters. "); for(ent=1; ent<=6; ent++) { printf("Please enter word %i: ", ent); scanf("%s", str); //if (str >= 65 && str <= 90) //{ printf(" "); k=0; while(str[k]) { //printf("%d ", str[k++]); count=count+1; k++; } //printf(" count is: %d ", count); if(count<5) { printf("Word is too short, please try again "); ent--; count = 0; } else if (count>12) { printf("Word is too long, please try again "); ent--; count = 0; } else { k=0; if (ent==1) { for (i=0; i< count; i++) game[i+4][1] = str[k++]; count = 0; } else if (ent == 2) { for (i=0; i< count; i++) game[i+7][11] = str[k++]; count = 0; } else if (ent == 3) { for (j=0; j< count; j++) game[2][j+1] = str[k++]; count = 0; } else if (ent == 4) { for (i=0; i< count; i++) for (j=0; j< count; j++) { game[i+7][j+12] = str[k++]; i++; } count = 0; } else if (ent == 5) { rev=23; for (j=count; j>0; j--) { game[6][rev] = str[k++]; rev--; } count = 0; } else { rev=16; i=0; for (j=count; j>0; j--) { game[i][rev] = str[k++]; rev--; i++; } count = 0; } } }//else //printf("Entries are not upper case!");} system("cls||clear"); printf(" Now that you have entered all your words, have fun finding them!!! "); printf(" "); for (j=0; j<=9; j++) printf("%3d", j); printf(" "); for (j=10; j<=23; j++) printf("%2d ", j); printf(" "); for (j=10; j<23; j++) printf("------"); printf(" "); for (i=0; i<=19; i++) { printf("%3d|", i); for (j=0; j<=23; j++) printf("%3c", game [i][j]); printf(" | "); } count=0; printf(" Enter the coordinates x,y of the first letter of each word. "); for(ent=1; ent<=6; ent++) { printf("Word #%d found: ", ent); scanf("%i,%i", &x, &y); if ((x==4 && y==1) || (x==7 && y==11) || (x==2 && y==1) || (x==7 && y==12) || (x==6 && y==23) || (x==0 && y==16)) printf("Good Job! "); else { printf("Try again! "); ent--; add++; if (add == 3) { printf(" Three failed tries already, maybe try a different puzzle? "); break; } } //else //{ //printf("wrong entry, try again! "); //word--; //} } break; default: printf("Please try running the program again "); break; } printf (" Would you like to run the program again? "); scanf (" %c", &var); }while(var == 'y'||var == 'Y'); system("cls||clear"); printf(" Thank you for using this program, come back soon! "); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started