Your problem is you are cout-ing the value of the functions ranged() and combat() instead of just calling them.
Your ranged() and combat() functions appear to already be printing out the information you desire so there is no need to print again at the end of the program.
If you wanted to return the information to the cout you would need to use
return
in the ranged or combat function to send the value back to the main function.
If you are happy printing in the ranged and combat function you could simply swap ranged and combat to void functions (because you weren't returning a value either way) and then it won't attempt to print out the value again.
I'm not sure what prints when you cout from a function without a returned value but I know you aren't suppose to do it that way. Either return a value or make it a void function and don't print.
Here would be an example using void functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
int a;//Base Strength
int b;//Final Damage
int w;//Weapon Bonus
int x;//Base Defense
int y;//Final Guard
int u;//Armor Bonus
int z;//Final Damage
int j;//Distance
int k;//Base Offense
int r;//Range Hit Chance
int v1;//Variable 1
int v2;//Variable 2
int v3;//Variable 3
void combat(){
v1 = rand() %3 + 1;//Variable for attacker
v2 = rand() %3 + 1;//Variable for defender
b = (a*(w/100)) + a;//Calculating attacker
y = (x*(u/100)) + x;//Calculating defender
z = (b*v1) - (y*v2);//Determining damage dealt
if (z<1)//Determines if damage is a hit or miss
cout << "Miss" << '\n';
else
cout << "Damage Dealt: " << z << '\n';}
void ranged(){
v3 = rand() %100 + 1;//Variable for accuracy
r = ((100-(j*10))+k);//Calculating accuracy
if (v3<=r)//Determines if you successfuly engage in combat
combat();
else
cout << "Miss" << '\n';}
int main(){
cout << "Enter Base Strength: ";
cin >> a;
cout << "Enter Weapon Bonus: ";
cin >> w;
cout << "Enter Base Defense: ";
cin >> x;
cout << "Enter Armor Bonus: ";
cin >> u;
cout << "Enter Base Offense: ";
cin >> k;
cout << "Enter Distance: ";
cin >> j;
srand (time(NULL));
if (j>0)
ranged();
else
combat();
return 1;
}
|
One other thing i notice is you are doing integer division, which is fine if you understand that means any information after a decimal place is lost. IE if you did 10 / 3 the value would be 3 instead of 3.333333.
If you want to use those decimal places you would need to use a different data type like float.