Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -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: make
17 changes: 17 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Containerized CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout mycode
uses: actions/checkout@v2
- name: Build myimage
run: docker build -t cpp-sandbox .
- name: Launch container
run: docker run cpp-sandbox cpplint *.cpp *.h
2 changes: 1 addition & 1 deletion GameDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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();
int roll = random() % roll_counter.size();
roll_counter[roll]++;
return roll + 1;
}
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[![Build C++](https://github.com/Manavi-ghorpade/Roller/actions/workflows/actions.yml/badge.svg)](https://github.com/Manavi-ghorpade/Roller/actions/workflows/actions.yml)

[![Containerized CI](https://github.com/Manavi-ghorpade/Roller/actions/workflows/docker-build.yml/badge.svg)](https://github.com/Manavi-ghorpade/Roller/actions/workflows/docker-build.yml)

# Roller


This repository provides a program that rolls a game die, such as the
six-sided dice used in traditional dice game.

Expand Down
5 changes: 2 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ 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"
<< "--------------------\n"
<< "Arguments\n"
<< "--------------------\n"
<< "<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;
Expand Down