dice3

Solutions on MaxInterview for dice3 by the best coders in the world

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