Rolling two dice - random

HELLO. Rolling two dice - random.
Dice 1-6.rolling ends when the 10. executed.

what can do?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <cstdlib>
#include <ctime>

int main()
{
    unsigned dice[2];
    std::srand(std::time(0));
    while (doce[0] + dice[1] != 10) {
        dice[0] = std::rand() % 6 + 1;
        dice[1] = std::rand() % 6 + 1;
        std::cout << "Rolled: " << dice[0] << " and " << dice[1] << std::endl;
    }
}

Is it what you want?
Last edited on
not..sorry my englis is bad.
Simulated rolling two dice. dice(1-6)-random

result :
-1. attempt (2,4)
- 2.attempt (5;5)
-3.attempt (6;1)
..
..
-10 attempt ->end
Change while loop condition:
1
2
3
4
5
int i = 0;
while(i < 10) {
/*...*/
++i;
}
Last edited on
yes i have do this. but my result is rolled 1 and 1234556789088658rolled.......and rolled 5 and 133456764544rolled..................
Last edited on
Sorry, I made mistake on line 11. Fixed that now. You could have spotted it yourself, and compiler should issue warning here. If it doesn't — find how to turn on warnings (or change compiler)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>	// vhodno-izhodni ukazi
#include <stdlib.h> //standardni ukazi
#include <string> 
#include <time.h>
using namespace std; // uporaba imenskega prostora	ni treba pisati std::ukaz

int main()
{
    int dice[6];
    srand(time(0));
    short i;
    i=0;
    
    while(i < 10)
     {
          i=i+1;
        dice[0] = rand() % 6 + 1;
        dice[1] = rand() % 6 + 1;
        cout << "Rolled: " << dice[0] << "    and     " << dice[1]<<endl;
    }
    system ("pause");
	return 0; 
}

this work ...
Topic archived. No new replies allowed.