hey guys I am new to the programming language and have an assignment due today and I am stuck on this. Its a scrable programming in C. I tried but cannot figure out how the main function should work out. Here is my code with the assignment instruction. If anyone can guide me through it.
Thanks
*************************************************************************************
Write an interactive program that will allow a user to play the word game Scramble. You will need to:
• Declare and use two character arrays:
o one for the “word to be guessed”
o one for the “scrambled word”
• Declare additional variables as needed
• Load the arrays
o “word to be guessed”
Read a word from the file and store it in the “word to be guessed” array.
o “scrambled word”
Read a word from the file and store it in the “scrambled word” array
Sample Output:
Welcome to Scramble
This is where you explain the instructions!
Here is the word: oerts
Select one of the following:
1 - Answer the entire word
2 - Get a hint before you guess
3 - I give up, show me the answer
1
Here's is the scrambled word: oerts
Enter your guess:
store
you have used 1 of your guesses
Great job!
Do you want to play again? (y/n): y
Here is the word: otcpail
Select one of the following:
1 - Answer the entire word
2 - Get a hint before you guess
3 - I give up, show me the answer
2
You are trying to unscramble: otcpail
Which letter do you need help with?: c
This is where c is located in the word
c------
Here's is the scrambled word: otcpail
Enter your guess:
coptail
you have used 1 of your guesses
Here is the word: otcpail
Select one of the following:
1 - Answer the entire word
2 - Get a hint before you guess
3 - I give up, show me the answer
1
Here's is the scrambled word: otcpail
Enter your guess:
coplait
you have used 2 of your guesses
Here is the word: otcpail
Select one of the following:
1 - Answer the entire word
2 - Get a hint before you guess
3 - I give up, show me the answer
1
Here's is the scrambled word: otcpail
Enter your guess:
captail
you have used 3 of your guesses
Here is the word: otcpail
Select one of the following:
1 - Answer the entire word
2 - Get a hint before you guess
3 - I give up, show me the answer
1
Here's is the scrambled word: otcpail
Enter your guess:
caplait
you have used 4 of your guesses
Better luck next time
The word was capitol
Do you want to play again? (y/n): y
Here is the word: umnot
Select one of the following:
1 - Answer the entire word
2 - Get a hint before you guess
3 - I give up, show me the answer
2
You are trying to unscramble: umnot
Which letter do you need help with?: m
This is where m is located in the word
m----
Here's is the scrambled word: umnot
Enter your guess:
motun
you have used 1 of your guesses
Here is the word: umnot
Select one of the following:
1 - Answer the entire word
2 - Get a hint before you guess
3 - I give up, show me the answer
3
The word you were trying to guess was mount
Better luck next time
The word was mount
Do you want to play again? (y/n): n
Come and play any time!
Press any key to continue . . .
**************************************************************************************
and here is my code so far....
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define SIZE 100
void Menu();//display the list of instrucitons
void Quit(char *again);//funciton for quiting the game
void clear(char default_array[SIZE]);//wipes out the arrays as the new game starts
int game_play_options();
int correct(char guess, char scrambled_word[SIZE], char word_to_be_guessed[SIZE], int *bad);
int main()//main function
{
char word_to_be_guessed[SIZE]={'\0'};//array for the word to be guesseed
char scrambled_word[SIZE]={'\0'};//array for the scrabled word
char guessed_word[SIZE]={'\0'};//array for the guessed word
char again='y';//for the quit funtion
char selection;//choice to play
char guess;//for users guess
int bad=0;//counter for wrong guesses
int progress;
FILE *inptr;
Menu();//calling menu funtion
inptr=fopen("words.txt", "r");//opening the file
while(again!='n' && again!='N')//if the user wants to play another game
{
clear(word_to_be_guessed);
clear(scrambled_word);
clear(guessed_word);
fscanf(inptr,"%s", word_to_be_guessed);
fscanf(inptr,"%s", scrambled_word);
printf("Guess this word\n");
printf("%s\n", scrambled_word);
selection=game_play_options();
if(selection =='c' || selection =='C')
{
printf("The word you were trying to guess was %s\n",word_to_be_guessed);
}
else if(selection =='a' || selection =='A')
{
printf("Okay now, guess the word\n");
scanf("%s",&guessed_word);
guess=guessed_word[SIZE];
progress=correct(guess, scrambled_word, word_to_be_guessed, &bad);
if(progress==0)
{
bad+=1;
}
if(bad==4)
break;
printf("You have guessed it wrong %d times\n", bad);
printf("You have %d wrong guess left\n", 4-bad);
}
else
{
printf("Please enter appropriate selection...\n");
}
Quit(&again);
}
fclose(inptr);//closing the file
return 0;
}
void Menu()
{
printf("******************************************************************\n\n");
printf(" WELCOME TO SCRABLE!!\n\n\n");
printf("Please read the following instructions before you play\n");
printf("You will be presented with a word which is not in order\n");
printf("Guess the word looking at the letters\n");
printf("You can have up to four incorrect guesses\n");
printf("The game will be OVER when you have guessed the correct word!!\n");
printf("OR when you have guessed incorrectly FOUR times.\n\n");
printf(" HAVE FUN!\n\n");
printf("****************************************************************** \n");
}
void clear(char default_array[SIZE])//wipes out the arrays as the new game starts
{
int i=0;
for(i=0; i<SIZE; i++)
{
default_array[i]='\0';
}
}
void Quit(char *again)//funciton for quiting the game
{
printf("Do you want to play another game(y/n)?");
scanf(" %c", again);
if(*again != 'y' && *again !='Y' && *again !='n' && *again !='N')
{
printf("Invalid selection, please chose(y/n)\n");
Quit(again);
}
}
int game_play_options()
{
char choice;
printf("Select one of the following:\n");
printf("a -Answer the entire word\n");
printf("b -Get a hint before you guess\n");
printf("c -I give up, show me the answer\n");
scanf("%c", &choice);
return choice;
}
int correct(char guess, char scrambled_word[SIZE], char word_to_be_guessed[SIZE], int *bad)
{
if(guess=word_to_be_guessed[SIZE])
{
printf("YOU GUESSED IT CORRECT!!!!!\n\n");
return 1;
}
else
printf("You have guessed it worng\n");
printf("Try again\n");
printf("%s",scrambled_word);
return 0;
}