How to roll the dice

Does anyone know rolling the dice program. I don't understand the meaning of the commands
I have this program and I need to redo it into all numbers not only 7 and also I need to make a graph of it. I just started to learn the program and our teacher doesn't explain us properly he showed us only once how to make lines in wxString program but did not explain anything. If someone can help me and explain commands please let me know or respond on this message.

int roll ()
{
return (rand()%6)+1+(rand()%6)+1 1.
}
int main()
srand(time(0)); 2.
int seven=0 3.
long counter=0 4.
int current;
while(counter<10000)
{
current=roll();
if(current==7)
count<<"WE have rolled the sum 7"<<endl;
seven+seven+1;
}
counter=counter+1; 5.
}
cout<<"We have rolled"<<seven<<"sum seven"<<endl;
system("pause");
}

!. Why we use rand %6+1+(
2.What does it mean
3.why seven =0
4. why we use command long , can we use another command?and again =0?
5 Why we use it between } }
And do you know how to make a graph or where can I find the information about the program that makes graph.
Again I only started to learn the programming and don't understand what are we doing ?


umm, first of all... this code doesn't work, second, please put it within code things like that
now, about your problem:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int roll ()   //creates a funtion
{
return (rand()%6)+1+(rand()%6)+1 1.  //returns a random integer value between 1-6 +1 + 1-6 +1
// basically this returns the sum of 2 dice rolls
}
int main()   // beginning of program, there should be a { at this location
srand(time(0)); 2.  // seeds the random number (allowing it to be random)
int seven=0 3.  // new variables in C++ aren't 0 by default, this makes it 0
long counter=0 4.  //long is like an int, you can use int, i've already explained =0
int current;
while(counter<10000)
{
current=roll();
if(current==7)
count<<"WE have rolled the sum 7"<<endl;
seven+seven+1;  //location 1
}  //this ends the while
counter=counter+1; 5.  //this should be at "location 1"
}  // this is incorrect
cout<<"We have rolled"<<seven<<"sum seven"<<endl;
system("pause");  // people on this forum HATE this command. do yourself a favor use getch ();
//you'll have to put #include <conio.h> at the top
}

this looks salvagable and interesting ask more questions if you need more help
I don't follow your post very well. Are you rolling 2 dice, as in the CRAPS game?

Write a program that mimics rolling 2 dice. I can't follow the program you posted.

1) use 2 random number generators each generating an integer between 1 and 6.
2) sum the two integers to yield the amount rolled.
3) apply the rules of the Craps game to the amount rolled through conditionals.

You will probably have to do some research on the rules of that dice game.
oh and i forgot seven+seven+1 does nothing and count<<"WE have rolled the sum 7"<<endl; is bad, use cout<<
Last edited on
Thank you so much I'll try to do the program and make a graphic for this. If I ll have a problem I ll need more help.Thanks a lot
Topic archived. No new replies allowed.