DEV Community

Tepid Angler
Tepid Angler

Posted on • Updated on

Moving Forward.cpp

This is gonna be a relatively short and sweet article. I recently began refreshing myself on C++ (post C++98) and that gave me an idea to possibly look into game development. Although I'm very aware it's frowned upon to code your own game engine, that's exactly what I will be doing. So to basically sum things up without being too winded, I'll be using this to post Hack the Box (HTB) write-ups of boxes that I pwn once they retire, and I've also thought of the possibility of detailing my game dev projects here. Anyway, stay tuned for more folks!

P.S. Below is a simple calculator program I wrote, it's available on my github page as well in the 'Calculator' repo. Feel free to improve it, break it or whatever you feel like doing. If you make it do something cool or unexpected definitely let me know. If you want to add algebraic functions or something similar that's also fine.

calc.cpp:

/* This is my first attempt at a calculator program. It will have the ability to add, divide, subtract, and multiply values given to it by the user */

#include <iostream>
#include <unistd.h>

int getValueFromUser()
{
    std::cout << "Enter an Integer please: ";
    int input{ 0 };
    std::cin >> input;
    std::cout << "[+] Storing value, please wait\n";
    sleep(2);
    return input;
}

int add(int x, int y)
{
    return x + y;
}

int multiply(int z, int w)
{
    return z * w;
}

int sub(int b, int c)
{
    return b - c;
}

int divide(int d, int e)
{
    return d / e;
}

void doCalc(int choice)
{
    int a{ };
    int s{ };
    int m{ };
    int di{ };

    switch(choice) {

        case 1 :
            a = ( add( getValueFromUser(), getValueFromUser() ));
            std::cout << "Your Total for addition is => " << a << "\n";
            std::cout << "\nThank you for using the Calculator\n";
            break;
        case 2 :
            s = sub( getValueFromUser(), getValueFromUser() );
            std::cout << "Your Total for subtraction is => " << s << "\n";
            std::cout << "\nThank you for using the Calculator\n";
            break;
        case 3 :
            m = multiply( getValueFromUser(), getValueFromUser() );
            std::cout << "Your Total for Multiplication is => " << m << "\n";
            std::cout << "\nThank you for using the Calculator\n";
            break;
        case 4 :
            di = divide( getValueFromUser(), getValueFromUser() );
            std::cout << "Your Total for Division is => " << di << "\n";
            std::cout << "\nThank you for using the Calculator\n";
            break;
        case 5 :
            std::cout << "Thanks for wasting your own time fam. You played yourself\n";
            exit (EXIT_SUCCESS);
            break;
        default :
            std::cout << "The Instructions were clear than a mothafucker dog, learn to read.\n";
            std::cout << "You know what fuck this shit I'm aborting\n";
            exit (EXIT_SUCCESS);
    }
}

int main()
{
    int choice{ 0 };
    std::cout << "Welcome to Tepi's original Calculator written in C++\n";
    std::cout << "Would you like do (1) Addition, (2) Subtraction, (3) Multiplication, (4) Division, or (5) Exit?\n>";
    std::cin >> choice;
    doCalc(choice);
    return 0;
}


Oldest comments (0)