diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..1c3a144 Binary files /dev/null and b/.DS_Store differ diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 0000000..a4c2d84 Binary files /dev/null and b/.github/.DS_Store differ diff --git a/.github/workflows/.DS_Store b/.github/workflows/.DS_Store new file mode 100644 index 0000000..8895faf Binary files /dev/null and b/.github/workflows/.DS_Store differ diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..3f6b690 --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,23 @@ +name: Build C++ + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + install: + runs-on: ubuntu-latest + steps: + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y -f build-essential g++ cmake + build: + needs: install + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build project + run: g++ GameDie.cpp main.cpp -std=c++17 -o firstIO diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..7a69b62 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,18 @@ +name: Docker Image CI + +on: + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build -t cpp . + - name: Run the lint + run: docker run -i cpp cpplint *.cpp *.h diff --git a/GameDie.cpp b/GameDie.cpp index d8ecb3a..7fc1fc4 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -9,14 +9,14 @@ GameDie::GameDie() { srand(time(NULL)); roll_counter.resize(FACES); - for (int i = 0; i < FACES; i++ ) - roll_counter[i] = 0; + for (int i = 0; i < FACES; i++) + roll_counter[i] = 0; } // overloaded constructor GameDie::GameDie(unsigned int num) { srand(time(NULL)); - if ( num == 0 ) { + if (num == 0) { roll_counter.resize(FACES); } else { roll_counter.resize(num); @@ -29,13 +29,14 @@ GameDie::GameDie(unsigned int num) { // generate a random number between 1-n where n is the counter size // (inclusive) and return it int GameDie::roll() { - int roll = rand_r() % roll_counter.size(); + unsigned int temp = 40; + int roll = rand() % roll_counter.size(); roll_counter[roll]++; return roll + 1; } // return the count of how many times each face has been rolled, as a vector // where each face's count is at index face-1 (i.e. Face 1 is at index 0) -vector GameDie::get_distribution() { +vector GameDie::get_distribution() { return roll_counter; } diff --git a/README.md b/README.md index d46f7c6..4931258 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,6 @@ To check for your program's adoption of the style guide, within the docker container (see above), run **cpplint**: `cpplint *.cpp *.h` + + +[![Build C++](https://github.com/sachinprasad1998mav/Roller/actions/workflows/actions.yml/badge.svg)](https://github.com/sachinprasad1998mav/Roller/actions/workflows/actions.yml) diff --git a/Roller b/Roller new file mode 100755 index 0000000..998ae82 Binary files /dev/null and b/Roller differ diff --git a/main.cpp b/main.cpp index 65055f9..39efd65 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,7 @@ using std::cout; using std::endl; int main(int argc, char *argv[]) { - if ( argc != 2 || std::atoi(argv[1]) < 1 ){ + if ( argc != 2 || std::atoi(argv[1]) < 1 ) { cout << "Incorrect command.\n" << "Format: ./Roller \n" << "--------------------\n" @@ -15,8 +15,7 @@ int main(int argc, char *argv[]) { << "--------------------\n" << " - Required; a number 1 or greater representing the number\n" << " of faces on the die being rolled\n"; - } - else { + } else { int faces = std::atoi(argv[1]); GameDie die(faces); cout << die.roll() << endl;