-
-
Save ZeBlobNH/582af54edba5f30f11c4 to your computer and use it in GitHub Desktop.
Weapons Comparator 4000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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