Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2012, 07:53 PM   PM User | #1
haze man
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
haze man is an unknown quantity at this point
Hangman C code

whats wrong with my hangman code?? it isnt assigning the arrays to be the word guessed, i know at the moment i have hard coded 'trick' to be guessed but even that doesnt work. Thanks in advance hope you can help!
here is the code:

#include <stdio.h>
#include <stdlib.h>
main()
{
printf("Welcome To Hangman \n \n \n") ;
printf("To play this game you have to guess the letter of the word that is picked \n \n") ;
printf("If you guess correct you will not lose any lives \n") ;
printf("However an incorect guess will cause you to lose one life \n") ;
printf("Good Luck! \n \n") ;


//random word select
srand(0) ;
int num = rand() %5 +1 ;

printf("%d \n", num) ;

flushall();

//assignment of random words to arrays
char array ;

if ( num == 1 )
{
char array[] = {'b','r','i','c','k'} ;
}

else
if ( num == 2)
{
char array[] = {'t','r','i','c','k'} ;
}

else
if ( num == 3)
{
char array[] = {'b','o','a','t','s'} ;
}

else
if ( num == 4 )
{
char array[] = {'m','e','n','u','s'} ;
}

else
if ( num == 5 )
{
char array[] = {'g','u','i','d','e'} ;
}

//To scan the users imput to the word to be guessed

int lives = 10 ;

printf("You have %d lives \n \n", lives) ;

char array1[] = {'t','r','i','c','k'} ;
char letter;
int i;

for (i = 0 ; i < 6 ; i++)
{
letter = (char)getchar();
scanf("%c", &letter);

if (letter == array1[i])
{

lives = lives ;
printf("Corrent you now have %d lives left \n \n", lives) ;
}
else
{
lives = lives --;
printf("Incorrect you now have %d lives left \n \n", lives) ;
}

flushall();

if ( lives <= 0)
printf("You lose") ;


}


getchar() ;

}// end to main
haze man is offline   Reply With Quote
Old 11-14-2012, 01:41 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
according to this link your arrays should be something like
Code:
char array1[] = "trick";
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 04:13 AM.


Advertisement
Log in to turn off these ads.