Skip to content

Instantly share code, notes, and snippets.

@ZeBlobNH
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZeBlobNH/582af54edba5f30f11c4 to your computer and use it in GitHub Desktop.
Save ZeBlobNH/582af54edba5f30f11c4 to your computer and use it in GitHub Desktop.
Weapons Comparator 4000
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int restart(1);
do
{
system("cls");
//first weapon
int diceOne(0), amelOne(0);
double faceOne(0);
cout << "First weapon :" << endl;
cout << "Enter the number of dice : ";
cin >> diceOne;
cout << "Enter the number of face : ";
cin >> faceOne;
cout << "Enter the amelioration : ";
cin >> amelOne;
//second weapon
int diceTwo(0), amelTwo(0);
double faceTwo(0);
cout << "Second weapon :" << endl;
cout << "Enter the number of dice : ";
cin >> diceTwo;
cout << "Enter the number of face : ";
cin >> faceTwo;
cout << "Enter the amelioration : ";
cin >> amelTwo;
cout << endl;
//calculation of the hopes (probability)
//E(aDb+c) = a * (1/b) * (b1+b2+b3+...+bn) +c
//E(aDb+c) = (a/b) * (b*(b+1)/2) + c
//E(aDb+c) = a * (b+1)/2 + c
int hopeOne(0), hopeTwo(0);
hopeOne = diceOne * (faceOne+1)/2 + amelOne;
hopeTwo = diceTwo * (faceTwo+1)/2 + amelTwo;
//Final
cout << "E(" << diceOne << "d" << faceOne << "+" << amelOne << ") = " << hopeOne << endl;
cout << "E(" << diceTwo << "d" << faceTwo << "+" << amelTwo << ") = " << hopeTwo << endl;
if (hopeOne < hopeTwo)
{
cout << "The first weapon is worse than the second weapon." << endl << endl;
}
else if (hopeOne > hopeTwo)
{
cout << "The first weapon is better than the second weapon." << endl << endl;
}
else
{
cout << "The weapons are equal each other." << endl << endl;
}
cout << "Press 1 to start again, 0 to quit : ";
cin >> restart;
}
while(restart == 1);
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment