Я выбрал свой первый проект на C ++, и я бы сделал предиктор смерти, который имел бы точные шансы на смерть и дал бы вам день рождения, в котором вы будете продолжать получать день рождения каждые 360 миллисекунд, пока в конце концов не умрете.
Проблема, с которой я сталкиваюсь, заключается в том, что я не знаю, как включить графики предварительной оценки в свою работу.
Я добавил только 1 из 19 if
заявления, потому что 600 строк кода в потоке было бы болезненно переживать. Как мне включить эти графики precentage, чтобы программа работала?
//GOOOD LUCK
#include "stdafx.h"#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <random>
using namespace std;
int main()
{
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis1 (1,28440); // Died under 1 year of
//age. 1.161756638 % chance
uniform_int_distribution<> dis2 (28441,33196); // Died between 1-4 years of
//age. 0.194279696 % chance
uniform_int_distribution<> dis3 (33197,36033); // Died between 5-9 years of
//age. 0.115889718 % chance
uniform_int_distribution<> dis4 (36034,39798); // Died between 10-14 years of
//age. 0.153797951 % chance
uniform_int_distribution<> dis5 (39799,53501); // Died between 15-19 years of
//age. 0.559759184 % chance
uniform_int_distribution<> dis6 (53502,74032); // Died between 20-24 years of
//age. 0.838678816 % chance
uniform_int_distribution<> dis7 (74033,93600); // Died between 25-29 years of
//age. 0.799340854 % chance
uniform_int_distribution<> dis8 (93601,115957); // Died between 30-34 years of
//age. 0.913264801 % chance
uniform_int_distribution<> dis9 (115958,147377); // Died between 35-39 years of
//age. 1.283487819 % chance
uniform_int_distribution<> dis10(147378,200742); // Died between 40-44 years of
//age. 2.179927672 % chance
uniform_int_distribution<> dis11(200743,280125); // Died between 45-49 years of
//age. 3.242747089 % chance
uniform_int_distribution<> dis12(280126,384272); // Died between 50-54 years of
//age. 4.254341371 % chance
uniform_int_distribution<> dis13(384273,511750); // Died between 55-59 years of
//age. 5.207398478 % chance
uniform_int_distribution<> dis14(511751,659573); // Died between 60-64 years of
//age. 6.038474388 % chance
uniform_int_distribution<> dis15(659574,831809); // Died between 65-69 years of
//age. 7.035735454 % chance
uniform_int_distribution<> dis16(831810,1057928); // Died between 70-74 years of
//age. 9.236823110 % chance
uniform_int_distribution<> dis17(1057929,1365816); // Died between 75-79 years of
//age. 12.57703684 % chance
uniform_int_distribution<> dis18(1365817,1744593); // Died between 80-84 years of
//age. 15.47280922 % chance
uniform_int_distribution<> dis19(1744594,2447762); // Died at age 85 and above.
// 28.72402438 % chance//REFERENCE: http://www.disastercenter.com/cdc/Death%20rates%202005.htmlfor (double count = 0; count < 101; count++)
{
int var1 = dis1(gen);
int var2 = dis2(gen);
int var3 = dis3(gen);
int var4 = dis4(gen);
int var5 = dis5(gen);
int var6 = dis6(gen);
int var7 = dis7(gen);
int var8 = dis8(gen);
int var9 = dis9(gen);
int var10 = dis10(gen);
int var11 = dis11(gen);
int var12 = dis12(gen);
int var13 = dis13(gen);
int var14 = dis14(gen);
int var15 = dis15(gen);
int var16 = dis16(gen);
int var17 = dis17(gen);
int var18 = dis18(gen);
int var19 = dis19(gen);
if (count < 102)
{
Sleep(360);
cout << "\n\t\t It's your birthday! You turned: " << count;
}
if (var1 > 1 && var1 > 28440)
{
cout << "\n\n\n\t\t\tYou died! Better luck next time!";
cout << "\n\n ";
Sleep(1000);
cout << "T "; Sleep(100);
cout << "H "; Sleep(100);
cout << "A "; Sleep(100);
cout << "N "; Sleep(100);
cout << "K "; Sleep(100);
cout << "S "; Sleep(100);
cout << " "; Sleep(100);
cout << "F "; Sleep(100);
cout << "O "; Sleep(100);
cout << "R "; Sleep(100);
cout << " "; Sleep(100);
cout << "P "; Sleep(100);
cout << "L "; Sleep(100);
cout << "A "; Sleep(100);
cout << "Y "; Sleep(100);
cout << "I "; Sleep(100);
cout << "N "; Sleep(100);
cout << "G "; Sleep(100);
cout << " "; Sleep(100);
cout << "\n\n\n\t\t\t ";
return 0;
Вы можете попробовать что-то вроде:
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<double> distribution(0, 100.);
unsigned int age = 0;
for (;;) {
auto percent = distribution(gen);
if (percent <= get_die_probability(age)) {
break;
}
++age;
std::cout << "It's your birthday! You turned: " << age << std::endl;
}
std::cout << "You die at " << age << std::endl;
Вам нужен вектор объектов равномерного распределения, а не миллионы переменных с индивидуальными именами.
typedef uniform_int_distribution<> dt;
vector<dt> dis;
int low= 0;
for (...stuff...) {
++low;
high= ...;
dis.push_back(dt(low,high));
}