Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write down theexact step-by-step execution of this code and it's... Write down theexact step-by-step execution of this code and it's output. Full marks will be

Write down theexact step-by-step execution of this code and it's...

Write down theexact step-by-step execution of this code and it's output. Full marks will be awarded for writing down the steps in correct order describing the exact execution of the code. Partial marks may be awarded for submissions that are missing minor details.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Tourism Concepts And Practices

Authors: John R Walker, Josielyn T Walker

1st Edition

0138142459, 9780138142452

More Books

Students also viewed these General Management questions

Question

LO13.1 Explain how completed reports affect your credibility.

Answered: 1 week ago

Question

Tell me about yourself.

Answered: 1 week ago