Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help writing this C code. C not C++ You are to make a fairly simple game. The ga

ID: 3582726 • Letter: H

Question

Help writing this C code.

C not C++

You are to make a fairly simple game.

The game will have two players (two humans, no need to try and make a computer player.

The game will be a form of combat between the players.

Each player should have 3 stats.

HP: Their health points, when this reaches 0, they lose.

Attack: How much "damage" each of their attacks do when they hit.

Defense: The amount of areas they can defend against in an attack.

Attack + Defense should total 10, while the minimum for each stat should be1.

Each player should also be able to enter their name (single word).

Each round of the game will consist of each player acting once as the attacker, and once as the defender.

Rounds will be continued until one of (or both of) the players has 0 hp remaining.

Combat works as follows:

The attack choose a number between 1 and 10 inclusive.

The defender then picks spots to defend, again from 1 to 10 inclusive.

So if the player has a defense of 3, they may choose to defend 3 numbers of 1-10.

The attack is defended if the defender picks one of these values.

In this event no damage is done to the defender.

If the attack is a hit (the attacker picked a number that the defender did not)

then the defender loses hp equal to the attack value of the attacker.

For this program you should assume you're working on a system with limited memory (so don't want memory)

You are only allowed to use a single array in your program, so use it wisely (odds are you'll want to use it for temporary storage of the player names).

You should also use functions to set up player info (name, attack and defense levels)

Functions should also be used to resolve combat.

Do not allow invalid stat entry (enforce the sum of attack + defense is 10, and neither stat can be 0)

Before each round you should print the player name and current hp level.

Explanation / Answer

#include <stdlib.h>
#include <iostream.h>
#include<stdio.h>
int combat();
int showIp(int ip, int enemyattack);

int showEnemyIp(int enemyip, int attack);
int battle;
int main()
{
    int battle;
    game(" name combat ");
    cout << " attack combat? Y = 1 N = 2 ";
    cin >> battle;
    if(battle==1)
    {
   cout << "comabt";
    }
    else if(battle==2)
    {
   cout << "You chose to not attack the combat. ";
    }
    else
    {
   cout << "not a correct choice. ";
   return main();
    }

game("pause");
return 0;
}

int comabt()
{
    int ip = 50, enemyip = 25, attack = 10, enemyattack = 5;

    int hitcombat;
    cout << " Hit comabt? Yes = 1 No = 2 ";
    cin >> hitcombat;
    if(hitcombat==1)
    {
      cout << " You hit the combat. ";
      cout << "The comabt now has " << showEnemyIp(enemyip, attack) << "IP left. ";
      cout << "The comabt hit you back. ";
      cout << "You now have " << showHp(ip, enemyattack) << "IP left. ";
    }
    else if(battle==2)
    {
   cout << "You chose not to hit the comabt so he was hit you instead ";
   cout << "You now have the " << showIp(ip, enemyattack) << "IP left. ";
    }
    else
    {
   cout << "That is not a valid choice. ";
    }
}

int showEnemyIp(int enemyip, int attack)
{
    return enemyip - attack;
}
int showIp(int ip, int enemyattack)
{
    return ip - enemyattack;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote