I figured out both of my other questions, but now I have a new problem.
BTW you can just type system("cls"); to clear screen.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{ /*variables*/
char name[101], help, action, play;
int php = 50, npchp = 50, dam, heal;
srand(time(NULL));
/*end variables*/
printf("Please enter your name: ");
fgets (name, 101 , stdin);
printf("Hello, %s" , name);
printf("Have you played this game before? (Y or N) ");
while((help = tolower(getchar())) && help != 'y' && help != 'n');
system("cls");
if(help == 'n')
printf("Enter the letter of the action you wish to perform, the object of this game is\nto kill the guy before he kills you.\n");
while(play == 'y'){
printf("\nWhat would you like to do?\n[A]ttack\n[R]un away\n");
while((action = tolower(getchar())) && action != 'a' && action != 'h' && action != 'r');
if(action == 'a'){
system("cls");
dam = (rand()%5)+1;
printf("You hit the guy for %i damage.\n", dam);
npchp = npchp - dam;
printf("The guy now has %i health\n\n", npchp);
if(npchp < 1){
system("cls");
printf("Congratulations, %sYou killed the guy!\n", name);
printf("Would you like to play again? (Y or N)\n");
while((play = tolower(getchar())) && play != 'y' && play != 'n');
if(play == 'n')
return 0;
if(play == 'y')
return 1;
}
dam = (rand()%5)+1;
printf("The guy hits you for %i damage.\n", dam);
php = php - dam;
printf("You now have %i health\n\n", php);
if(php < 1){
system("cls");
printf("The guy killed you, you lose!");
printf("Would you like to play again? (Y or N)\n");
while((play = tolower(getchar())) && play != 'y' && play != 'n');
if(play == 'n')
return 0;
if(play == 'y')
return 1;
}
}
if(action == 'r'){
system("cls");
printf("You run away.\nYou didn't kill the guy, you lose.");
printf("Would you like to play again? (Y or N)\n");
while((play = tolower(getchar())) && play != 'y' && play != 'n');
if(play == 'n')
return 0;
if(play == 'y')
return 1;
}
}
Here is my code, I do not have enough "}" but I can't figure out where.