histogram c++

#include<iostream>
#include<cstdlib>
#include<ctime> 
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm> 


int main( ) {
    std::cout << "enter seeding number: " ; 
    int num_seed = 0 ;
    std::cin >> num_seed ;
    srand( num_seed ) ;
    std::cout << "enter numbers of tries: ";
    int tries = 0 ;
    std::cin >> tries ;
    std::cout << "enter numbers of asterikes: "; 
    int asterikes = 0 ;
    std::cin >> asterikes ;

    double sum_of_three_dices , average_of_three_dices,sigme_dices_powered, variation, standard_dev = 0.0 ;
    std::vector<size_t> vec_of_three_dice(19,0);
    for(size_t i = 0; i < tries ; i++)
    {
        int dice_one = rand()%6 + 1 ;
        int dice_two = rand()%6 + 1 ;
        int dice_three = rand()%6 + 1 ;
        vec_of_three_dice[dice_one + dice_two + dice_three] += 1 ;
        sum_of_three_dices += dice_one + dice_two +dice_three ;
        average_of_three_dices = sum_of_three_dices / tries ;
        sigme_dices_powered += pow(dice_one + dice_two + dice_three ,2);
        variation = sigme_dices_powered/tries - pow(average_of_three_dices,2);
        standard_dev = sqrt(variation);
    }

    average_of_three_dices = sum_of_three_dices / tries ;
    std::cout << "average_of_three_dices is: " <<std::fixed << std::setprecision(3) << average_of_three_dices << std::endl;
    std::cout << "standard deviation is: " <<std::fixed << std::setprecision(3) << standard_dev << std::endl;
    std::cout << std::endl;
    // creating a histogram 
    int max_value = *max_element(vec_of_three_dice.begin(),vec_of_three_dice.end());
    for(size_t i = 3; i <vec_of_three_dice.size() ; i ++ ){
        if(i < 10 ){
            std::cout <<std::setw(2) <<std::setfill(' ') << i<< " : " <<"("<<std::setw(4)<<std::setfill(' ')<<vec_of_three_dice.at(i) << ")" ;
        }else{
            std::cout << i << " : " <<"("<<std::setw(4)<<std::setfill(' ')<<vec_of_three_dice.at(i) << ")";
        }
       for(size_t j = 0; j <= static_cast<size_t>(vec_of_three_dice.at(i) * asterikes)/max_value ; j++ ){
           std::cout << "*";
       }
        std::cout << std::endl;


    } 

    

    return 0 ;
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source