Thread: Need help solving simple C question, need help with code

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    Need help solving simple C question, need help with code

    What the programme is suppose to do: User will enter a name and if its "JACK SON BOY", the progamme will state that he is a douchebag else progamme will state that he is not a douchebag. Help me check whats wrong with my code

    Here is my code

    Code:
    //"Are you a douchebag test"//
    #include <stdio.h>
    char main()
    {
        char name;
        printf("Enter you name/n");
        scanf(%c,&name);
        if (name == JACK SON BOY)
        printf( " you are a douchebag\n");
        else if (name != JACK SON BOY )
        printf(" you are not a douchebag\n");
        return 0;
    }
    Thanks in advance

  2. #2
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    - You are declaring main wrong, it should normally be int main(void) or int main(int argc, char *argv[])
    - your newline character is wrong, it should be \n not /n.
    - name is just a single char, it cannot contain the entire name, you need to change it into an array of chars
    - your scanf statement is wrong, the first argument should be in quotes, and it will only read a single char into name, since you are using %c (%s is used for strings)
    - you cannot compare strings with the == operator, you must resort to strcmp(...) from string.h
    - you need to indent your code properly


    Good work there, almost as many errors as lines of code

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    haha thanks so much

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by qawsed51 View Post
    What the programme is suppose to do: User will enter a name and if its "JACK SON BOY", the progamme will state that he is a douchebag else progamme will state that he is not a douchebag. Help me check whats wrong with my code
    Best way to fix your code.... Climb into a C Programming textbook and start reading...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help solving a question
    By everyone0 in forum C Programming
    Replies: 9
    Last Post: 05-06-2010, 11:09 AM
  2. Simple question, trying to understand this code...
    By matthayzon89 in forum C Programming
    Replies: 11
    Last Post: 03-23-2010, 01:04 PM
  3. simple code question
    By potatopuff in forum C Programming
    Replies: 7
    Last Post: 07-15-2008, 01:31 AM
  4. Simple C++ question. Error in code somewhere.
    By Paracropolis in forum C++ Programming
    Replies: 10
    Last Post: 02-06-2006, 08:59 AM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM