May 16, 2013 at 4:49pm UTC
HELLO. Rolling two dice - random.
Dice 1-6.rolling ends when the 10. executed.
what can do?
May 16, 2013 at 4:58pm UTC
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 May 16, 2013 at 5:32pm UTC
May 16, 2013 at 5:12pm UTC
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
May 16, 2013 at 5:21pm UTC
Change while loop condition:
1 2 3 4 5
int i = 0;
while (i < 10) {
/*...*/
++i;
}
Last edited on May 16, 2013 at 5:22pm UTC
May 16, 2013 at 5:29pm UTC
yes i have do this. but my result is rolled 1 and 1234556789088658rolled.......and rolled 5 and 133456764544rolled..................
Last edited on May 16, 2013 at 5:30pm UTC
May 16, 2013 at 5:33pm UTC
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)