// © Copyrights 2026 Praajna Pattada

#include <iostream>
#include <limits>

char UserInput {}; // A variable to store the user's response
double a {};
double b {};
double result {};

/* A function which presents options to the user. Called at the beginning of the program, like a main menu. */
void Ask()
{
    std::cout << "What would you like to do? Enter the respective number and press Enter." << '\n';
    std::cout << '\n' << "1: Addition" << '\n' << "2: Subtraction" << '\n' << "3: Multiplication" << '\n' << "4: Division"  << '\n' << "5: Quit this program" << '\n' << '\n';
    std::cin >> UserInput;
}

void ReceiveInput()
{
    std::cout << '\n' << "Enter the first number: ";
    std::cin >> a;
    std::cout << "Enter the second number: ";
    std::cin >> b;
}

void Add(double x, double y)
{
    result = x+y;
    std::cout << '\n' << "The sum of " << a << " and " << b << " is " << '\n' << result << '\n';
    std::cout << "----------------------" << '\n';
}

void Subtract(double x, double y)
{
    result = x-y;
    std::cout << '\n' << b << " subtracted from " << a << " is " << '\n' << result << '\n';
    std::cout << "----------------------" << '\n';
}

void Multiply(double x, double y)
{
    result = x*y;
    std::cout << '\n' << "The product of " << a << " and " << b << " is " << '\n' << result << '\n';
    std::cout << "----------------------" << '\n';
}

void Divide(double x, double y)
{
    result = x/y;
    std::cout << '\n' << a << " divided by " << b << " is " << '\n' << result << '\n';
    std::cout << "----------------------" << '\n';
}

int main()
{
    do {
        Ask();
        
        /* It is necessary to use quotation marks while mentioning the numbers, to compare them with the response of the user */
        if (UserInput == '1')
        {
            ReceiveInput();
            Add(a, b);
        } else if (UserInput == '2') {
            ReceiveInput();
            Subtract(a, b);
        } else if (UserInput == '3') {
            ReceiveInput();
            Multiply(a, b);
        } else if (UserInput == '4') {
            ReceiveInput();
            Divide(a, b);
        } else if (UserInput != '5') {
            std::cout << "You have not entered a valid selection. Please try again." << '\n';
            std::cout << "----------------------" << '\n';
        }
    } while (UserInput != '5');

    std::cout << "Thank you for using this calculator." << '\n' << "----------------------" << '\n';
    
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    std::cin.get();
    return 0;
}
