NextVox
← Back to the magazine
codingCasualCalculators8th grade

the terminal calculator

by Luffy · August 30, 2026

Hearts help pick each month’s winners.

The code
#include <iostream>
#include <string>
#include <cmath>
#include <thread>
#include <chrono>
#include <type_traits>

using namespace std;
using namespace chrono;

template <typename T>
void actualThing() {
    string op = "";
    bool go = true;
    string gointp;
    T int1, int2;

    while (go==true) {
        if (go==false) {
            break;
        }
        cout << "What's your first number?\n";
        cin >> int1;
        if (cin.fail()) {
            cout << ">>>An internal error (I&FE-4 (1stLTRINT)) has occurred. Please try again.\n";
            return;
        }
        if (is_same<T, double>::value && (int1>1e150||int1<-1e150)) {
            cout << "You serious? That number's too far from 0. Please rerun the program and choose another, smaller number";
            return;
        }
        cout << "What is your operator sign?\nOptions: ADD, SUB, MULT, DIV\n";
        cin >> op;
        cout << "What's your second number?\n";
        cin >> int2;
        if (cin.fail()) {
            cout << ">>>An internal error (I&FE-3 (2ndLTRINT)) has occurred. Please try again.\n";
            return;
        }
        if (is_same<T, double>::value && (int2>1e150||int2<-1e150)) {
            cout << "You serious? That number's too far from 0. Please rerun the program and choose another, smaller number";
            return;
        }
        if (op=="ADD") {
            cout << int1+int2 << " <<answer\n";
        } else if (op=="SUB") {
            cout << int1-int2 << " <<answer\n";
        } else if (op=="MULT") {
            cout << int1*int2 << " <<answer\n";
        } else if (op=="DIV"&&int2==0) {
            cout << "UNDEFINED (detected ?/0) <<answer\n";
        } else if (op=="DIV"&&int2!=0) {
            cout << int1/int2 << " <<answer\n";
        } else {
            cout << ">>>An internal error (I&FE-1 (OPRERR)) has occurred. Please try again.\n";
            return;
        }

        cout << "Make a new calculation? (Y/N)\n";
        cin >> gointp;
        if (gointp=="Y") {
            go=true;
        } else if (gointp=="N") {
            go=false;
        } else {
            cout << ">>>An internal error (I&FE-2 (CNTRQT)) has occurred. Please try again.\n";
            return;
        }
    }
}

int main() {
    cout << "Loading files." << flush;
    this_thread::sleep_for(milliseconds(320));
    cout << "." << flush;
    this_thread::sleep_for(milliseconds(1270));
    cout << ".\n" << flush;
    cout << "Loading processing packages...\n" << flush;
    this_thread::sleep_for(milliseconds(672));
    char PILDC;
    cout << "PRELOAD INSERT: [L]ongs (up to ~9.2e18) OR [D]oubles (up to ~1e150)?\n";
    cin >> PILDC;
    cout << "Rechecking preinstalled packages and beginning program startup...\n" << flush;
    this_thread::sleep_for(milliseconds(195));
    system("clear");
    cout << endl << "*/ / / / / / / / / / / / / / / / / / / / /*\nNOTE:\nSome errors has been found and marked by the creator as I&FEs, short for Internal&FoundErrors.";
    cout << "\nIf that happens, the program will most likely stop by itself OR execute a specialized function to fix the bug\n*/ / / / / / / / / / / / / / / / / / / / /*\n\n";

    if (PILDC=='L') {
        actualThing<long long>();
    } else {
        actualThing<double>();
    }
    return 0;
}