Hello.
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.
Thanks.
Code:
#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");
scanf("%s",target);
printf("you are now attacking a %s\n",target);
if(target=="GOBLIN")
{
printf("goblin is killed!\n");
printf("plus 20xp!\n");
xp=xp+20;
}
if(target=="RED ONION")
{
printf("red onion is killed!\n");
printf("plus 40xp!\n");
xp=xp+40;
}
if(target=="GIANT RAT")
{
printf("giant rat is killed!\n");
printf("plus 80xp!\n");
xp=xp+80;
}
void delay() /* the delay function which tells he user the fight is currently underway */
{
for(i=3;i=0;i--)
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);
getchar(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 */
else
printf("Pardon? Please give a valid response in a Yes/No format, please.\n");
return(0);
}