First off, heres my code.
Code:
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <time.h>
using namespace std;
string Command;
struct User
{
int UHP; // Users Current Hit Points
int max_UHP; // Users Maximum Hit Points
};
struct Challenger
{
int CHP; // Challengers Current Hit Points
int max_CHP; // Challengers Maximum Hit Points
};
int main()
{
srand( time(NULL) );
User Player;
Challenger Enemy;
Player.max_UHP = 100; // Users Maximum Health Points
Player.UHP = 100; // Users Current Health Points
int UATK = rand()%20; // Users Attack Points
int UDF = rand()%20; // Users Defence Points
int UACC = rand()%10; // Users Accuracy Points
int UAGT = rand()%10; // Users Agility Points
Enemy.max_CHP = 100; // Challengers Maximum Health Points
Enemy.CHP = 100; // Challengers Current Health Points
int CATK = rand()%15; // Challengers Attack Points
int CDF = rand()%15; // Challengers Defence Points
int CACC = rand()%10; // Challengers Accuracy Points
int CAGT = rand()%10; // Challengers Agility Points
cout<<"As your walking down a path a cloaked swordsman ambushes you.\n";
cout<<"He then challenges you to a fight and you humbly accept.\n";
do{
cout<<"Your turn:\n";
cin>>Command;
cin.ignore();
if(Command=="Attack"||Command=="attack"){
if(UACC >=6 && CAGT >=6){Enemy.CHP-=(UATK-=CDF);
cout<<UATK<<" Damage!\n";
cout<<"He blocked "<<CDF<<" damage.\n";
cout<<"Him: "<<Enemy.CHP<<"/"<<Enemy.max_CHP<<"\n";}
else if(UACC >=6){Enemy.CHP-=UATK;
cout<<UATK<<" Damage!\n";
cout<<"Him: "<<Enemy.CHP<<"/"<<Enemy.max_CHP<<"\n";}
else(UACC <=5);{
cout<<"Miss\n";}
}
cout<<"He attacks.\n";
Player.UHP-=CATK;
cout<<"You lost "<<CATK<<" hp.\n";
cout<<"You: "<<Player.UHP<<"/"<<Player.max_UHP<<"\n";
}while(Player.UHP >=0 || Enemy.CHP >=0);
cin.get();
}
This is a battle program Im working on. In the code it subtracts the defenders defence from the attackers attack then subtracts the rest from the defenders health points
ex : Enemy.CHP-=(UATK-=CDF)
now my problem is if the defence is higher than the attack it adds the remaining points to the defenders health. How can I stop it from doing that.
Second problem, I heard that the way Im using rand isnt exactly the right and best way to use it. I agree because my numbers arent very random at all. Can someone tell me how I would fix this and work into my code?