really new to coding dice game

I used my first code to simply + - * / 2 numbers and this is my 2nd code :D was really curious if this is ok for an exe representing 2 dice being thrown?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <cstdlib>
#include <ctime>
Using namespace std;
Int a,b;
Int main(){
  cout << "Press ENTER to roll";
if (cin.get() == '\n');
do {srand (time(0));
    a = 1 + (rand()%6);
    b = 1 + (rand()%6);
  cout << a << " " << b << endl;
  cout << "press ENTER to roll again OR press ANY KEY then ENTER to quit";
while (cin.get() == '\n');
return 0;}


Thank you for any ideas or feedback u have :)
Last edited on
I had to change a few things in order to get it to work properly...

had to remove the capitol I from "int" and the capital U from "using". Also missing for formatting "{ }" to define the "if" statement and the closing out the "while". had to cast the int on the srand statement to avoid an implicit conversion error...

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

int main()
{
    int a,b;
    
    cout << "Press ENTER to roll";
    if (cin.get() == '\n')
    {
        do
        {
            srand( static_cast<unsigned int>(time(NULL)));
            a = 1 + (rand()%6);
            b = 1 + (rand()%6);
            cout << a << " " << b << endl;
            cout << "press ENTER to roll again OR press ANY KEY then ENTER to quit";
        } while (cin.get() == '\n');
    }
    return 0;
}
Last edited on
Sorry I think my auto type added some upper case, next time I post Il double check that :) thank you for looking at the code :D iv only just started learning with codebox. the way u changed the srand statement is awesome, I like that way better than the way I had it :D took me afew tries using rand before it worked for me lol. Il defo look into it more so I can use it better Thank u again, its really kewl getting someone else's perspective :D
you're welcome...

I figured you got autocorrected. I'm also new to c++, and start class for it in a month. I've done a lot of programming in VBA and VB.Net though, and some PHP.

I've never used codebox, Right now I'm using Xcode on a Macbook for c++.
Hope your class goes well, sure it will with the experience u have to take with u :) I like the ide (meant codeblocks***, I shouldn't be typing on a Saturday night lol) xcode is a better name tho, iv just been learning afew weeks for fun, started with c++ as Id like to write my own basic game if I get good enough :)
Last edited on
Topic archived. No new replies allowed.