# Thread: C++ Code - A simple challenge

1. ## C++ Code - A simple challenge

I was recently chatting in an AIM chatroom and someone started rolling dice. You know "ONLINE HOST rolls two 6 sided dice. 3 4"
I know it's good to try and write programs that solve annoying things for some good programming practice. So I figured I would try and write a program that does the same thing as the dice rolling. Now I havent actually sat down with my compiler and tryed writing a program to do such a thing yet. I figure since this is the first time trying to solve a problem like this, I'll see how it's done first. (that and I'm not to good with cpp yet, I only know the basics. I'm just learning how to use functions now) So what I'm saying is I'm proposing a dice rolling code challenge. I know writing a code to do this will be extremly easy for most of you, but I would just kinda like to see how you guys do it.

I figure the only things you would have to use to solve this problem is just use a few variables and if else statements. Using functions would probably help too right? I'm interested to see how this would be coded.

2. Using rand would probably be the way. Look it up if you want more. This sounds too much like hw. So, I am going to have to tell you to look it up.

3. Lol, not homework at all. I dont even have any classes dealing with computer programming. I'm taking basic GED classes at the moment. It just kinda caught my attention while I was chatting and I figured it would be a good way to put some of the things I learned to use. I guess I'll just try to put together some code in a bit and see if I can come any where near to getting it to work. I havent used rand to much though. Only used it once in a little program for a guessing game. I should be able to kinda piece together some code though. I'll post it when I'm done. Thanks.

4. Each dice could be a separate rand call.

srand(time(NULL));
short dice1=(int) rand()%6 + 1;
short dice2=(int) rand()%6 + 1;
cout<<"the first dice rolled "<<dice1<<endl;
cout<<"the second dice rolled "<<dice2<<endl;

5. The following code is using the ranodom.h because that is the one we are using in my cs class. It is available at http://lpdatafiles.com/data/cpluspc/RANDOM.H

Code:
```#include <iostream.h>
#include <c:\random.h>
#include <conio.h>

int main()
{
randomize();
for (int i=1; i<=2; i++)
{
cout << "roll "<< i << ": " << 1 + random(6) << endl;
}
getch();
return 0;
}```

6. Maybe it should be #include <random.h> or if it´s user defind function #include "random.h"