/*
* Copyright 2023, Ali Arya
* Anyone Can Code: Algorithmic Thinking
* Example 4.6c
*/

#include <iostream>
using namespace std;

//operation modules
int Add(int num1, int num2)
{
    return num1 + num2;
}
int Sub(int num1, int num2)
{
    return num1 - num2;
}
int Mul(int num1, int num2)
{
    return num1 * num2;
}
int Div(int num1, int num2)
{
    if (num2 == 0)
    {
        cout << "divid eby zero!\n";
        return NULL;
    }
    else
        return num1 / num2;
}

//main code
int main()
{
    int operation, num1, num2;
    bool quit = false;
    while (!quit)
    {
        cout << "Enter operation type.  1 for add, 2 for subtract, 3 for multiply, 4 for divide, 0 to exit: ";
        cin >> operation;
        if (operation > 0 && operation < 5)
        {
            cout << "Enter the first number: ";
            cin >> num1;
            cout << "Enter the second number: ";
            cin >> num2;
        }
        if (operation == 0)
            quit = true;
        else if (operation == 1)
            cout << Add(num1, num2);
        else if (operation == 2)
            cout << Sub(num1, num2);
        else if (operation == 3)
            cout << Mul(num1, num2);
        else if (operation == 4)
            cout << Div(num1, num2);
        else
            cout << "Invalid operation!";
        cout << "\n";
    }
	return 0;
}