My code is:
Code:#include "header.h" int main(){ int PAttack, PDefense; int EAttack, EDefense; int PDmgDealt, EDmgDealt; int PHP = 100, Php; int EHP = 100, Ehp; char input[4+1]; int choice; Ehp = EHP - PDmgDealt; Php = PHP - EDmgDealt; srand(time(NULL)); do{ PAttack = rand() % 50 + 1; EDefense = rand() % 50 + 1; EAttack = rand() % 50 + 1; PDefense = rand() % 50 + 1; printf("1. Attack\n"); printf("2. Skill\n"); printf("3. Item\n"); printf("4. Run\n"); fgets(input, 4, stdin); choice = atoi(input); attacking( choice, PAttack, EDefense, PDmgDealt, EHP, Ehp, EAttack, PDefense, EDmgDealt, PHP, Php); } while(Ehp != 0); return 0; }Code:#include "header.h" void PDmgChk(int PAttack,int EDefense,int PDmgDealt, int EHP, int Ehp){ PDmgDealt = PAttack - EDefense; // If Player's Attack is equal to the Enemy's Defense then do nothing if(PAttack == EDefense){ PDmgDealt = 0; printf("You've dealt no damage"); printf("The enemy now has %d", Ehp); printf(" HP\n"); } // If Player's Attack is greater then the Enemy's Defense, deal damge else if(PAttack > EDefense){ printf("You've dealt "); printf("%d", PDmgDealt); printf(" damage\n"); printf("The enemy now has %d", Ehp); printf(" HP\n"); } // If Player's Attack is less then the Enemy's defense do nothing. else if(PAttack < EDefense){ PDmgDealt = 0; printf("You've dealt no damage! \n"); printf("The enemy now has %d", Ehp); printf(" HP\n"); } // Shows Player's Attack and Enemy's Defense REMOVE BEFORE FININSHING. printf("%d \n", PAttack); printf("%d\n" , EDefense); } void EDmgChk(int EAttack, int PDefense, int EDmgDealt, int PHP, int Php){ EDmgDealt = EAttack - PDefense; // If Enemy's Attack is equal to Player's Defense, do nothing. if(EAttack == PDefense){ EDmgDealt = 0; printf("The Enemy dealt no damage to you\n"); printf("You now have %d", Php); printf(" HP\n"); } // If Enemy's Attack is greater than the Player's Defense, deal damage. if(EAttack > PDefense){ printf("The Enemy dealt "); printf("%d", EDmgDealt); printf(" damage to you.\n"); printf("You now have %d", Php); printf(" HP\n"); } // If Enemy's Attack is less than the Player's Defense, do nothing. if(EAttack < PDefense){ EDmgDealt = 0; printf("The Enemy dealt no damage to you.\n"); printf("You now have %d", Php); printf(" HP\n"); } printf("%d\n", EAttack); printf("%d\n", PDefense); }
Code:#include "header.h" void attacking(int choice, int PAttack, int EDefense, int PDmgDealt, int EHP, int Ehp, int EAttack, int PDefense, int EDmgDealt, int PHP, int Php) { switch (choice){ case 1: Attack(PAttack, EDefense, PDmgDealt, EHP, Ehp); EDmgChk(EAttack, PDefense, EDmgDealt, PHP, Php); break; case 2: Skill(); EDmgChk(EAttack, PDefense, EDmgDealt, PHP, Php); break; case 3: Item(); EDmgChk(EAttack, PDefense, EDmgDealt, PHP, Php); break; case 4: Run(); break; } } void Attack(PAttack, EDefense, PDmgDealt, EHP, Ehp){ PDmgChk(PAttack, EDefense, PDmgDealt, EHP, Ehp); } void Skill(){ } void Item(){ } void Run(){ }
(Yes, I'm a newbie to coding, and sorry for the messy code.)
But anyways everything else works here, but receiving -1073741510 upon termination of the program.



LinkBack URL
About LinkBacks




