Thread: Beginner - Needing some help with script

  1. #1
    Registered User
    Join Date
    Jun 2013

    Exclamation Beginner - Needing some help with script


    I am currently writing a script as a test to see how hard it would be to make a mini-program on command prompt.

    I am new to C programming and I have been using 'C for Dummies'.

    I have written this code. Please tell me where I have gone wrong and where I can improve; I hope the annotations help you.


    #include <stdio.h>
    void delay(void); /* prototyping the delay function */
    double xp; /* this is the global variable which holds the user's experience acquired */
    int main()
        int x; /* this refers to the 'x' employed at the end of this code */
        char target[10]; /* refers to the selection of the monster and the response */ 
        int i;
        printf("time to kill a monster\n");
        printf("select your target:\n");
        printf("GOBLIN, RED ONION, GIANT RAT\n");
        printf("you are now attacking a %s\n",target);
        printf("goblin is killed!\n");
        printf("plus 20xp!\n");
      if(target=="RED ONION")
        printf("red onion is killed!\n");
        printf("plus 40xp!\n");
      if(target=="GIANT RAT")
        printf("giant rat is killed!\n");
        printf("plus 80xp!\n");
    void delay() /* the delay function which tells he user the fight is currently underway */
        printf("you swing your sword!\n");
                  printf("looks like you've killed a %s!\n",target);
                  printf("you currently have %d experience!\n",xp);
                  printf("would you like to fight another animal?\n",response);
                  if(response=='Y' || response =='y')
                  /* need to find a command that tells the compiler to re-run the program, of course remembering the xp acquired */
                  if(response=='n' || response =='N')
                  /* need to tell the compiler to end the script if 'n'/'N' is answered */
                  printf("Pardon? Please give a valid response in a Yes/No format, please.\n");

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Nice, France
    In C we compare strigns with strcmp, not with the operator ==.
    Code - functions and small libraries I use

    It’s 2014 and I still use printf() for debugging.

    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    In line 47 you start defining of the function delay inside main

    Generally - you should do it outside the main, in this line just call the function
    call to your function will look like
    To be or not to be == true

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Needing help to reduce the damge_bar of the ship (Beginner)
    By DecoratorFawn82 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2013, 06:52 AM
  2. Beginner Needing Help making change
    By jp1978 in forum C++ Programming
    Replies: 8
    Last Post: 03-22-2012, 04:17 PM
  3. Beginner Needing Help
    By MadProfessor in forum C Programming
    Replies: 4
    Last Post: 08-08-2005, 04:31 PM
  4. C++ script and needing on conversions
    By Ryan Mosby in forum C++ Programming
    Replies: 0
    Last Post: 10-05-2003, 04:50 PM
  5. Beginner needing help in C language
    By chauncey005 in forum C Programming
    Replies: 2
    Last Post: 09-26-2003, 02:04 PM

Tags for this Thread