diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..fa84d3ac --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: Build C++ + +on: + push: + branches: "**" + 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@v4 + - name: Build projects + run: g++ -std=c++17 main.cpp \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..54b6da1c --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +[![Build C++](https://github.com/tojustis/MyFirstExample/actions/workflows/test.yml/badge.svg)](https://github.com/tojustis/MyFirstExample/actions/workflows/test.yml) diff --git a/main.cpp b/main.cpp index 5411e7a3..f57141e9 100644 --- a/main.cpp +++ b/main.cpp @@ -16,10 +16,17 @@ int main() cout << "Addition: " << x + y << endl; cout << "Subtraction: " << x - y << endl; cout << "Multiplication: " << x * y << endl; - cout << "Division: " << x / y << endl; - cout << "Remainder: " << x % y << endl; + // This prevents a divide by zero error + // Made change for github actions + if (y == 0) { + cout << "Divide by zero is not a number\n"; + } else { + cout << "Division: " << x / y << endl; + cout << "Remainder: " << x % y << endl; + } cout << "Square Root: " << sqrt(x) << endl; cout << "Square: " << pow(x, y) << endl; + return 0; }