Random number between 1-6

So I'm writing this program that let you roll a dice and show you the random number, but I want the program to show how many 1,2,3 etc that you get when you roll. For example, You rolled '4' ones. You rolled '3' twos etc. This is the code I have this far. I know that I haven't declared the variabel x but that is just an example of how I think it might work. End when I run the program know it only shows 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;

int main ()
{
    int num;
    
    cout << "How many times do you want to roll the dice? ";
    cin >> num;

    int random = rand()% 6 + 1;
    for( int i=1; i<=num; i++)
        cout << random << endl;
    
    if(random==1)
        cout << "You rolled" << x << "ones" << endl;
    if(random==2)
        cout << "You rolled" << x <<"twos" << endl;
    if(random==3)
        cout << "You rolled" << x << "threes" << endl;
    if(random==4)
        cout << "You rolled" << x << "fours" << endl;
    if(random==5)
        cout << "You rolled" << x << "fives" << endl;
    if(random==6)
        cout << "You rolled" << x << "sixes" << endl;
    
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <random>
#include <ctime>
#include <iomanip>

int main()
{
    const int NROLLS = 6'000'000 ;
    const int MIN_VALUE = 1 ;
    const int MAX_VALUE = 6 ;
    const int ARRAY_SZ = MAX_VALUE + 1 ;

    // http://en.cppreference.com/w/cpp/numeric/random
    std::mt19937 rng( std::time(nullptr) ) ; // random number engine (seeded with current time)
    std::uniform_int_distribution<int> die( 1, 6 ) ; // fair die

    // frequencies of 1, 2, 3, 4, 5, 6 frequency_count[0] is not used
    int frequency_count[ARRAY_SZ] {} ; // initialise to all zeroes

    // readable tags for 1, 2, 3, 4, 5, 6 "zeroes" is not used
    const char* frequency_name[ARRAY_SZ] { "zeroes", "ones", "twos", "threes", "fours", "fives", "sixes" } ;

    // roll the die NROLLS times and update frequencies
    for( int n = 1 ; n < NROLLS ; ++n ) ++frequency_count[ die(rng) ] ;

    // print the results
    for( int i = MIN_VALUE ; i < ARRAY_SZ ; ++i )
        std::cout << "you rolled " << std::setw(7) << frequency_count[i] << ' ' << frequency_name[i] << '\n' ;
}

http://coliru.stacked-crooked.com/a/e6f696f97045711f
http://rextester.com/BFNK23897
Nothing more to add.

Except maybe to use std::bind() from <functional>.
Topic archived. No new replies allowed.