diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 00000000..a286f4b5 --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,25 @@ +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 project + run: g++ -std=c++17 main.cpp + + diff --git a/main.cpp b/main.cpp index 5411e7a3..93d0ef6f 100644 --- a/main.cpp +++ b/main.cpp @@ -10,16 +10,28 @@ int main() cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; cout << "Hi, please enter two whole numbers: "; - int x,y; + int x, y; - cin >> x >> y; - 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; - cout << "Square Root: " << sqrt(x) << endl; - cout << "Square: " << pow(x, y) << endl; + std::cin >> x >> y; + std::cout << "Addition: " << x + y << std::endl; + std::cout << "Subtraction: " << x - y << std::endl; + std::cout << "Multiplication: " << x * y << std::endl; + + if (y != 0) { + std::cout << "Division: " << x / y << std::endl; + std::cout << "Remainder: " << x % y << std::endl; + } else { + std::cout << "Division: undefined (division by zero)" << std::endl; + std::cout << "Remainder: undefined (division by zero)" << std::endl; + } + + if (x >= 0) { + std::cout << "Square Root: " << sqrt(x) << std::endl; + } else { + std::cout << "Square Root: undefined (negative number)" << std::endl; + } + + std::cout << "Power: " << pow(x, y) << std::endl; return 0; }