dice game c 2b 2b with standard deviation

Solutions on MaxInterview for dice game c 2b 2b with standard deviation by the best coders in the world

showing results for - "dice game c 2b 2b with standard deviation"
Gaia
18 Aug 2019
1#include<iostream>
2#include<cstdlib>
3#include<ctime> 
4#include<iomanip>
5#include<vector>
6#include<cmath>
7#include<algorithm> 
8
9int main( ) {
10    std::cout << "enter seeding number: " ; 
11    int num_seed = 0 ;
12    std::cin >> num_seed ;
13    srand( num_seed ) ;
14    std::cout << "enter numbers of tries: ";
15    int tries = 0 ;
16    std::cin >> tries ;
17    std::cout << "enter numbers of asterikes: "; 
18    int asterikes = 0 ;
19    std::cin >> asterikes ;
20
21    double sum_of_three_dices , average_of_three_dices,sigme_dices_powered, variation, standard_dev = 0.0 ;
22    std::vector<size_t> vec_of_three_dice(19,0);
23    for(size_t i = 0; i < tries ; i++)
24    {
25        int dice_one = rand()%6 + 1 ;
26        int dice_two = rand()%6 + 1 ;
27        int dice_three = rand()%6 + 1 ;
28        vec_of_three_dice[dice_one + dice_two + dice_three] += 1 ;
29        sum_of_three_dices += dice_one + dice_two +dice_three ;
30        average_of_three_dices = sum_of_three_dices / tries ;
31        sigme_dices_powered += pow(dice_one + dice_two + dice_three ,2);
32        variation = sigme_dices_powered/tries - pow(average_of_three_dices,2);
33        standard_dev = sqrt(variation);
34    }
35
36    average_of_three_dices = sum_of_three_dices / tries ;
37    std::cout << "average_of_three_dices is: " <<std::fixed << std::setprecision(3) << average_of_three_dices << std::endl;
38    std::cout << "standard deviation is: " <<std::fixed << std::setprecision(3) << standard_dev << std::endl;
39    std::cout << std::endl;
40    
41    int max_value = *max_element(vec_of_three_dice.begin(),vec_of_three_dice.end());
42    for(size_t i = 3; i <vec_of_three_dice.size() ; i ++ ){
43        if(i < 10 ){
44            std::cout <<std::setw(2) <<std::setfill(' ') << i<< " : " <<"("<<std::setw(4)<<std::setfill(' ')<<vec_of_three_dice.at(i) << ")" ;
45        }else{
46            std::cout << i << " : " <<"("<<std::setw(4)<<std::setfill(' ')<<vec_of_three_dice.at(i) << ")";
47        }
48       for(size_t j = 0; j <= static_cast<size_t>(vec_of_three_dice.at(i) * asterikes)/max_value ; j++ ){
49           std::cout << "*";
50       }
51        std::cout << std::endl;
52
53
54    } 
55
56    
57
58    return 0 ;
59}