Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Array of pointers
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Thu Nov 17, 2005 7:58 pm   Post subject: (No subject)

And yet, still no indentation in the main function.

Also, when you use indentation, use it consistently. Don't indent with two spaces in some places and three in another.
Sponsor
Sponsor
Sponsor
sponsor
Tubs




PostPosted: Thu Nov 17, 2005 8:05 pm   Post subject: (No subject)

c:

#include <stdio.h>

int guessing (char target[5], char prev[25], char *cg);
void display (char guessed[25], char solved[5]);

int main(int argc, char *argv[])
{

  int guesses, status, i, j;
  char guessed[26], word[6] = {'d', 'o', 'n', 'k', 'e', 'y'} , solved[6];
  char current_guess;

  printf ("HANGMAN:\n");

  for (i = 0; i < 26; ++i)
  {
     guessed[i]= '*';
  }
  for (i = 0; i < 6; ++i)
  {
     solved[i] = '-';
  }

  printf ("How many guesses would you like to have> ");
  scanf ("%d", &guesses);
  printf ("\n");

  for (i = 0; i <= guesses; ++i)
  {
     display(guessed, solved);
     status = guessing(word, guessed, &current_guess);
     for (j = 0; j < 6; j++)
     {
        if (status == i)
        {
           printf ("You got the letter %c!\n", word[i]);
           solved[i] = word[i];
        }
     }

      if (status == 6)
        printf ("That letter is incorrect, try again!\n");
      else if (status == 7)
        printf ("That letter has already been guessed, try again!\n");
  }

  printf ("\n");
  printf ("");
  system ("pause");

  return 0;
}

int guessing (char target[5], char prev[25], char *cg)
{

  char letter;
  int j, i, char_code;

  printf ("Guess a letter:> ");
  scanf ("% c", letter);
  char_code = (int)letter;

  for (i = 0; i < 26; i++)
  {
     if (char_code == prev[i])
        return 7;
  }

  if (letter == 'd')
     return 0;
  else if (letter == 'o')
     return 1;
  else if (letter == 'n')
     return 2;
  else if (letter == 'k')
     return 3;
  else if (letter = 'e')
     return 4;
  else if (letter == 'y')
     return 5;
  else
     return 6;
}

void display (char guessed[25], char solved[5])

{

  int i;

  printf ("You have used the letters: ");

  for (i = 0; i <= 25; ++i)
  {
     printf ("%c", guessed[i]);
  }

  printf ("\n");
  printf ("The word so far is: ");

  for (i = 0; i <= 5; ++i)
  {
     printf ("%c", solved[5]);
  }

  printf ("\n");
}


I didn't see any places where I incremented incorrectly Confused
wtd




PostPosted: Thu Nov 17, 2005 8:18 pm   Post subject: (No subject)

c:
int main(int argc, char *argv[])
{

  int guesses, status, i, j;
  char guessed[26], word[6] = {'d', 'o', 'n', 'k', 'e', 'y'} , solved[6];
  char current_guess;

  printf ("HANGMAN:\n");

  for (i = 0; i < 26; ++i)
  {
     guesse


Notice how when you indent the contents of the function, you use two spaces? You do that consistently, which is good, but...

When you get to something like the for loop, you indent 3 spaces. Smile
Tubs




PostPosted: Thu Nov 17, 2005 8:21 pm   Post subject: (No subject)

Ah ok. So now that the indenting issue is out of the way, any ideas on where the logic error(s) is?
wtd




PostPosted: Thu Nov 17, 2005 8:31 pm   Post subject: (No subject)

Well, one error at a time.

Line 61:

c:
scanf ("% c", letter);


The space between "%" and "c" will cause a problem, as will the fact that you are using "letter", which passes the value of the variable, rather than "&letter", which passes a pointer to that variable.
Tubs




PostPosted: Thu Nov 17, 2005 8:35 pm   Post subject: (No subject)

I was told to do that to bypass some logic error that occurs when the return key is hit before the scanf, and the value for return is used in place of the letter.
Tubs




PostPosted: Thu Nov 17, 2005 8:41 pm   Post subject: (No subject)

In fact, it happens right here. After you enter the amount of guesses you want, it records the return as the letter you want to guess.
Tubs




PostPosted: Thu Nov 17, 2005 8:43 pm   Post subject: (No subject)

I put the space in the wrong spot. Rolling Eyes
Sponsor
Sponsor
Sponsor
sponsor
Tubs




PostPosted: Thu Nov 17, 2005 9:51 pm   Post subject: (No subject)

Ok, I think I caught all of them. I will post the program once its done Smile
Tubs




PostPosted: Thu Nov 17, 2005 10:06 pm   Post subject: (No subject)

Ok, here is #1 done. Game of life next ... Confused Thank you so much for your help wtd Very Happy


Project 7 Q1.zip
 Description:

Download
 Filename:  Project 7 Q1.zip
 Filesize:  2.05 KB
 Downloaded:  99 Time(s)

[Gandalf]




PostPosted: Thu Nov 17, 2005 10:08 pm   Post subject: (No subject)

It would help if you didn't make 5 consecutive posts Evil or Very Mad. You should know well enough there is an edit button, and that posts like "I will post the program once its done" are not neccessary.
[Gandalf]




PostPosted: Thu Nov 17, 2005 10:10 pm   Post subject: (No subject)

Well, silly me, there is no edit button! Still, limit your posts to important things.

I don't like this idea of no 'edit' button in help forums, it really causes more trouble than it solves (afaik).
md




PostPosted: Thu Nov 17, 2005 10:18 pm   Post subject: (No subject)

Why is there no edit button?! Tony... I blame tony...
wtd




PostPosted: Thu Nov 17, 2005 10:37 pm   Post subject: (No subject)

Hopefully you realize that an executable tells me precisely squat. Smile
Tubs




PostPosted: Thu Nov 17, 2005 10:39 pm   Post subject: (No subject)

wtd wrote:
Hopefully you realize that an executable tells me precisely squat. Smile


Yes I do Smile It was just to show off.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 45 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: