OK so I switched compilers and now got that program to work with flying colors, now on to a bigger program that I have been wanting to make for a very long time. I will post the code I have so far and comment on it as to where I am having issues. First of all know that this is the first part of what will (eventually) be a much larger program.
Ok I am not getting any error messages but if I input certain numbers the program will only produce a 0 instead of the correct data.
The concept is that two ships are going to fight and combat is based on their stats (power, tracking, armor, and maneuverability) power and armor work against each other and tracking and maneuverability work against each other.
I am testing with these numbers but have had the same outcome with several other sets
atp = 7
att = 3
ata = 9
atm = 2
athp and dfhp really don,t matter other than how long the loop lasts
dfp = 3
dft = 6
dfa = 2
dfm = 9
#include <iostream>
using namespace std;
short atp, att, ata, atm, dfp, dft, dfa, dfm;
float hit;
double dam;
double athp, dfhp;
short shot;
int main ()
{
cout << "input attackers power, tracking, armor, maneuverability, and HP";
cin >> atp;
cin >> att;
cin >> ata;
cin >> atm;
cin >> athp;
cout << "input defenders power, tracking, armor, maneuverability, and HP";
cin >> dfp;
cin >> dft;
cin >> dfa;
cin >> dfm; //line 20
cin >> dfhp;
while (athp>0 && dfhp>0)
{
hit = (att / dfm) / 2 * 100; //this line fails when the equation would produce a fraction at any point, instead it produces only 0, even when the end number should be greater than 0
shot = rand() % 100 + 1;
cout << "shot is " << shot << "hit is " << hit << endl; //reference data
if (hit>shot)
{ //line 28
dam = atp / dfa; //this line will not produce an output less than 0 such as .33 and will round any decimal values
cout << "damage is " << dam << endl;
dfhp = dfhp - dam;
}
cout << "Defenders HP is:" << dfhp << endl;
hit = (dft / atm) / 2 * 100; //this line fails when the equation would produce a fraction at any point, instead it produces only 0, even when the end number should be greater than 0
shot = rand() % 100 + 1;
cout << "shot is " << shot << "hit is " << hit << endl; //reference data
if (hit>shot)
{
dam = dfp / ata;
cout << "damage is " << dam << endl;
athp = athp - dam; //this line will not produce an output less than 0 such as .33 and will round any decimal values
}
cout << "Attackers HP is:" << athp << endl;
}
if (athp>0 && dfhp<=0)
{
cout << "attacker wins";
}
else if (dfhp>0 && athp<=0)
{
cout << "defender wins";
}
else
{
cout << "tie, all is lost";
}
return 0;
}
So any ideas on why I am having these issues??
Edited by hispaladin, 21 June 2013 - 03:29 PM.