Zilvia.net Forums | Nissan 240SX (Silvia) and Z (Fairlady) Car Forum

Go Back   Zilvia.net Forums | Nissan 240SX (Silvia) and Z (Fairlady) Car Forum > Specific Topics > Off Topic Chat

Off Topic Chat All non related chat goes here.


Reply
 
Thread Tools Display Modes
Old 04-15-2011, 10:13 PM   #1
youngfab59
Zilvia Member
 
youngfab59's Avatar
 
Join Date: Jul 2010
Location: FL
Posts: 208
Trader Rating: (10)
youngfab59 has a little shameless behavior in the past
Feedback Score: 10 reviews
Send a message via AIM to youngfab59 Send a message via Yahoo to youngfab59
Help w/ C Programming Assignment

Hey everyone I really need help with my C programming assignment. I'm having trouble with my void Menu function getting my main function to read the inputs correctly. I've been trying for almost an hour and a half and still no luck with getting it to work. Also I need some help with my winOrLose function since its supposed to tell the user if they guessed correctly or if they used 4 guesses they lose. I really would appreciate any help. Here's my code

/*
Mario Gutierrez
COP 2220
Prof. Slavik
Assignment #4 - Scramble

*/

#define _CRT_SECURE_NO_DEPRECATE
//Maximum amount of guesses is 4
#define MAX_GUESSES 4
#define SIZE 20
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <string.h>

//Gives the user a hint if the user is having trouble with the word
void Hint(char word[], char scramble[]);
//Reads the users word guess
void aGuess(char word[], char scramble[]);
//Determines if the user wins or loses
void WinOrLose(char word[], char scramble[]);
//Retrieve the scrambled and unscrambled word from the text file
void Words(FILE * fileptr, char word[], char scramble[]);
//Menu will appear and ask the user to enter a selection
void Menu();
//Plays an entire game of scramble
void Play(char word[], char scramble[], int *selection, char again);
//Ask the user if they want to play again
void Quit(char *again);
//If the user chooses "3" this will give the user the word and tell the user they lose.
void GiveUp(char word[], char again);

int main()
{
//variables
char again ='y';
char word[SIZE], scramble [SIZE];
int selection;
FILE *fileptr;
//Open the text file with the words
fileptr = fopen("words.txt", "r");
//Instructions
printf("Welcome to Scramble\n");
printf("You will be given a scrambled word which you will try to guess.\nYou will be given four chances to guess the word\nand you'll be able to get hints if you feel stumped.\nGood Luck!!\n\n");
Quit(&again);
//Will continue to run the game if user chooses (Y)
while (again == 'y' || again == 'Y')
{
Words(fileptr, word, scramble);
Menu();
Play(word, scramble, &selection, again);
Quit(&again);
}
return 0;
}

void Words(FILE *fileptr, char word[], char scramble[])
{
int i;
char sSize, wSize;
fscanf(fileptr, "%s %s", word, scramble);
sSize = strlen(scramble);
wSize = strlen(word);
for (i=0; i<sSize; i++)
{
scramble[i] = tolower(scramble[i]); //change the letters in the scrambled word to lowercase
}
for (i=0; i<wSize; i++)
{
word[i] = tolower(word[i]); //change the letters in the actual word to lowercase
}
printf("Here's the scrambled word: %s\n\n", scramble);
return;
}

void Menu(int *selection)
{
selection = 0;
printf("Select one of the following:\n");
printf("1 - Enter the entire word\n");
printf("2 - Get a hint before you guess\n");
printf("3 - I give up, show me the answer\n");
scanf(" %d", &selection);
return;
}

void Play(char word[], char scramble[], int *selection, char again)
{
if (*selection == 1)
{
aGuess(word,scramble);
}
else if (*selection == 2)
{
Hint(word, scramble);
}
else
{
GiveUp(word, again);
}
}

void aGuess(char word[], char scramble[])
{
char guess[SIZE];
int Guesses;
Guesses = 0;
printf("Enter your guess: ", guess);
while (Guesses <= MAX_GUESSES)
{

if (strcmp (guess, word) == 0)
{
Guesses += 0;
}
else
{
Guesses += 1;
}

}

}

void Hint(char word[], char scramble[])
{
int i; int length; char letter;
printf("Which letter do you need help with?: ");
scanf(" %c", &letter);
length = strlen (word);
printf("\nThis is where %c is located in the word\n", letter);
for (i=0; i<length; i++)
{
if (word[i] == letter)
{
printf("%c", letter);
}
else
{
printf("*");
}


}
printf("\n\n");
}

void WinOrLose(char word[], char scramble[])
{
int win;
win = 0;
while (win == 0)
{
strcmp(word, scramble);
}
}

void Quit(char *again)
{
printf("Do you want to play? ");
scanf(" %c", &again);
}

void GiveUp(char word[], char again)
{
printf("The word you were trying to guess was: %s", word);
Quit(&again);
}
youngfab59 is offline   Reply With Quote
Sponsored Links
Old 04-15-2011, 10:37 PM   #2
KiLLeR2001
Post Whore!
 
Join Date: Jun 2007
Location: オーランドフロリダ
Posts: 7,955
Trader Rating: (46)
KiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud ofKiLLeR2001 has much to be proud of
Feedback Score: 46 reviews
First problem I see is you have a Menu(); yet your function is calling an int pointer based on how you set it up "void Menu(int *selection)" instead you need to send the selection value to the Play function.

edit: I actually see a handful of problems but I don't even know where to begin X_X
__________________
KiLLeR2001 is offline   Reply With Quote
Reply

Bookmarks



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
vB.Sponsors
Copyright ? 1998 - 2022, Zilvia.net