i am trying to write a simple turn based rpg game in void attack of course this is where they attack each other, in the code i set characters attack and subtract that from the targets health but when the code runs it adds the total can someone give me some advice about this
//header file
#pragma once
#include<iostream>
#include<stdio.h>
#include <string>
using namespace std;
cout<<name<<"'s attack did "<<characters::strength<<" damage to "<<target.name<<endl;
characters::strength-=target.health;
cout<<target.name<<" health is now "<<target.health - characters::strength<<endl;
return target.health - characters::strength ;
}
void attack(characters target) //problem is here
{
cout<<name<<"'s attack did "<<characters::strength<<" damage to "<<target.name<<endl;
characters::strength-=target.health;
cout<<target.name<<" health is now "<<target.health - characters::strength<<endl;
return target.health - characters::strength ;
}
You declare attack as having no return value, but then you try to return a value?
Also, the minus operator alone does not affect anything. I think you want something like this for line 7 above: target.health -= characters::strength;