my debugger screen is grey, I tried to do this....but I couldnt
User 11155132
Posts
-
hangman code in C -
hangman code in Chello guys, i have to write a simple project ... it is a hangman code in C# i have this...but when I run it... i keeps printing twice some sentences... if anybody can help me... and if the user type something different from l ..when it is asked...everything goes wrong...
#include <stdio.h>
#include <string.h>/* contant declarations */
#define NUM_TRIES_ALLOWED 10/* function prototypes */
main()
{
/* variable declarations */
int num_letters = 0, /* length of word char array */
count = 0, /* for word char array */
tries = 0, /* total tries user has used */
num_vis_chars = 0, /* # of visible characters */
correct_guesses = 0, /* # of correct guesses */
correct_flag = 0, /* was guess correct? */
repeat_flag = 0, /* was guess a repeat? */
choice;char guess,guessword;
/* array declarations */
char word[255] = " ";
char incorrect_letters[255] = " ";
/* get word */
puts( "Enter a word for player to guess." );
gets( word );printf("Ready to start!\n");
num_letters = strlen( word );
char visible_word[num_letters]; /* displays correct guesses *//* initialize visble_word */
for( count = 0; count < num_letters; count++ )
visible_word[count] = '*';visible_word[num_letters] = '\0';
if (guess == visible_word[count]){
while( tries < NUM_TRIES_ALLOWED )
{printf( "The word is: %s\\n\\n", visible\_word ); printf("Number of turns remaining: %d", NUM\_TRIES\_ALLOWED-tries); printf("\\nWould you like to guess the word \[w\] or guess a letter \[l\]:"); choice = getchar(); if (choice=='l'){ printf( "\\nWhat letter have you chosen?:\\t " ); scanf( " %c", &guess );} /\* match guess against previous guesses \*/ for( count = 0; count < num\_letters; count++ ) if( guess == visible\_word\[count\] || guess == incorrect\_letters\[count\] ) { repeat\_flag = 1; correct\_flag = 1; break; } if( repeat\_flag == 0 ) /\* check for matches in string \*/ for( count = 0; count < num\_letters; count++ ) { if( guess == word\[count\] ) { visible\_wo
-
hangman code in Chello guys, i have to write a simple project ... it is a hangman code in C# i have this...but when I run it... i keeps printing twice some sentences... if anybody can help me... and if the user type something different from l ..when it is asked...everything goes wrong...
#include <stdio.h>
#include <string.h>/* contant declarations */
#define NUM_TRIES_ALLOWED 10/* function prototypes */
main()
{
/* variable declarations */
int num_letters = 0, /* length of word char array */
count = 0, /* for word char array */
tries = 0, /* total tries user has used */
num_vis_chars = 0, /* # of visible characters */
correct_guesses = 0, /* # of correct guesses */
correct_flag = 0, /* was guess correct? */
repeat_flag = 0, /* was guess a repeat? */
choice;char guess,guessword;
/* array declarations */
char word[255] = " ";
char incorrect_letters[255] = " ";
/* get word */
puts( "Enter a word for player to guess." );
gets( word );printf("Ready to start!\n");
num_letters = strlen( word );
char visible_word[num_letters]; /* displays correct guesses *//* initialize visble_word */
for( count = 0; count < num_letters; count++ )
visible_word[count] = '*';visible_word[num_letters] = '\0';
if (guess == visible_word[count]){
while( tries < NUM_TRIES_ALLOWED )
{printf( "The word is: %s\\n\\n", visible\_word ); printf("Number of turns remaining: %d", NUM\_TRIES\_ALLOWED-tries); printf("\\nWould you like to guess the word \[w\] or guess a letter \[l\]:"); choice = getchar(); if (choice=='l'){ printf( "\\nWhat letter have you chosen?:\\t " ); scanf( " %c", &guess );} /\* match guess against previous guesses \*/ for( count = 0; count < num\_letters; count++ ) if( guess == visible\_word\[count\] || guess == incorrect\_letters\[count\] ) { repeat\_flag = 1; correct\_flag = 1; break; } if( repeat\_flag == 0 ) /\* check for matches in string \*/ for( count = 0; count < num\_letters; count++ ) { if( guess == word\[count\] ) { visible\_word\[