I can't be bothered asking 20 question, so I just guessed this is what you want. I offer no guarentees that this works let alone is anything close to what you are trying to make.
Code:
#include <iostream>
#include <string>
using namespace std;
void status(string &, string &, bool);
void status(string shooter, string target, bool targetAlive)
{
std::cout << shooter << " shoots at " << target << ". " << target << " is "
<< (targetAlive ? "alive" : "dead") << "." << std::endl;
}
void shoot(bool& targetAlive, double accuracy) // Single Shot Function
{
double r = 0.1*(rand()%11); // Computes Random Number
if (r < accuracy) // Random Number Less Then Accuracy
{
targetAlive = false;
}
}
string startDuel(bool aaronAlive, bool bobAlive, bool charlieAlive, double aa, double bb, double cc)
{
int round = 1;
do
{
cout << "Round #" << round << " : " << endl;
if (aaronAlive)
{
std::cout << "Aaron's turn. ";
if (charlieAlive)
{
shoot(charlieAlive, aa);
status("Aaron","Charlie",charlieAlive);
}
else
{
shoot(bobAlive, aa);
status("Aaron","Bob",bobAlive);
}
}
if (bobAlive)
{
std::cout << "Bob's turn. ";
if (charlieAlive)
{
shoot(charlieAlive, bb);
status("Bob","Charlie",charlieAlive);
}
else
{
shoot(aaronAlive, bb);
status("Bob","Aaron",aaronAlive);
}
}
if (charlieAlive)
{
std::cout << "Charlie's turn. ";
if (bobAlive)
{
shoot(bobAlive, cc);
status("Charlie","Bob",bobAlive);
}
else
{
shoot(aaronAlive, cc);
status("Charlie","Aaron",aaronAlive);
}
}
round ++;
}while((aaronAlive && bobAlive) || (aaronAlive && charlieAlive) || (bobAlive && charlieAlive));
if(aaronAlive)
{
return "Aaron ";
}
else if (bobAlive)
{
return "Bob ";
}
else if (charlieAlive)
{
return "Charlie ";
}
else return "No one ";
}
int main ()
{
srand((unsigned)time(NULL));
string winner_;
int Aaron = 0, Bob = 0, Charlie = 0, i;
for (i=0;i<=1000;i++)
{
winner_ = startDuel(true, true, true , 0.33, 0.50, 1.00);
if(winner_.compare("Aarron ") == 0)
{
Aaron++;
}
else if(winner_.compare("Bob ") == 0)
{
Bob++;
}
else if(winner_.compare("Charlie ") == 0)
{
Charlie++;
}
}
cout << endl << " -- RESULTS -- " << endl << endl;
cout << "Aaron won " << Aaron << " times !" << endl;
cout << "Bob won " << Bob << " times !" << endl;
cout << "Charlie won " << Charlie << " times !" << endl << endl;
system("pause");
return 0;
}
Edit to add:
Bob has some serious hax btw. In the gaming community I'm involved in, we'd ban him for having an aimbot.
Code:
-- RESULTS --
Aaron won 0 times !
Bob won 417 times !
Charlie won 181 times !
Code:
-- RESULTS --
Aaron won 0 times !
Bob won 405 times !
Charlie won 184 times !
Code:
-- RESULTS --
Aaron won 0 times !
Bob won 385 times !
Charlie won 221 times !
Darn those accuracy values.