Question: I need a walkthrough for this please. 01 #include 02 03 #define INITIAL_HEALTH 100 04 #define NAME_LENGTH 10 05 06 struct Hero 07 { 08
I need a walkthrough for this please.
01#include
02
03#define INITIAL_HEALTH 100
04#define NAME_LENGTH 10
05
06struct Hero
07{
08char name[NAME_LENGTH + 1];
09int health;
10int strength;
11int shield;
12};
13
14struct Hero attack(struct Hero* h1, struct Hero* h2)
15{
16struct Hero result;17
18while (h1->health > 0 && h2->health > 0)
19{
20h1->health -= h2->strength - h1->shield;
21h2->health -= h1->strength - h2->shield;
22}
23
24if (h1->health < h2->health)
25{
26result = *h1;27}
28else
29{
30result = *h2;
31}
32
33return result;
34}
35
36int main(void)
37{
38struct Hero hero1 = { {'N', 'i', 'n', 'j', 'a', ''} , INITIAL_HEALTH, 150, 20 };
39struct Hero hero2 = { "Enigma", INITIAL_HEALTH, 75, 50 };
40
41struct Hero winner = attack(&hero1, &hero2);
42
43puts("Game Over");
44printf("The winner is %s", winner.name);
45
46return 0;
47}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
