Simple gas station calculator for Windows After reading some beginner textbooks on C++ programming, I decided to write a trivial unit conversion program. Since I am working on Windows, the console windows still use codepage 850 by default, and I wanted to output the Euro currency sign. I also wanted to get the error handling right, since that's one of the topics beginner books often ignore. And, since I'm German, I wanted to use the appropriate decimal separators.

Now my "trivial" program has become quite large. Does it have to be that large? Is there some way to make it smaller, without giving up one of its features?

#include &lt;cstdlib&gt;
#include &lt;iomanip&gt;
#include &lt;iostream&gt;
#include &lt;locale&gt;
#include &lt;string&gt;

#include &lt;Windows.h&gt;

class SwitchToUtf8 {
private:
    UINT in;
    UINT out;
public:
    SwitchToUtf8() {
        in = GetConsoleCP();
        out = GetConsoleOutputCP();
        SetConsoleCP(65001);
        SetConsoleOutputCP(65001);
    }
    ~SwitchToUtf8() {
        SetConsoleCP(in);
        SetConsoleOutputCP(out);
    }
};

int main() {
    SwitchToUtf8 temporarily;

    std::locale::global(std::locale(""));
    std::wcin.imbue(std::locale());
    std::wcout.imbue(std::locale());
    std::wcerr.imbue(std::locale());

    const double price_per_liter = 1.31;

    std::wcout &lt;&lt; "How much gas did you refuel? ";
    std::wcin.sync();

    double liter;
    if (std::wcin &gt;&gt; liter) {
        double price = liter * price_per_liter;
        std::ios::fmtflags saved_flags(std::wcout.flags());
        std::wcout &lt;&lt; "That sums up to " &lt;&lt; std::fixed &lt;&lt; std::setprecision(2) &lt;&lt; price &lt;&lt; " €.\n" &lt;&lt; saved_flags;
        std::wcout &lt;&lt; price &lt;&lt; "\n";
    }
    else {
        std::wcin.clear();

        std::wstring line;
        if (std::getline(std::wcin, line)) {
            std::wcerr &lt;&lt; "Input error: " &lt;&lt; line &lt;&lt; "\n";
        }
        else {
            std::wcerr &lt;&lt; "Other error\n";
        }
    }
}
Firstly, I want to commend you on the neatness of your code. Appropriate spacing and newlines used make it very readable, even if some lines are slightly long. Also, you used the std:: namespace tag over the using namespace std; line, which is again, better practice in C++.

Now to answer your question, this code is not that large. When you compare it to the simplest possible program for a gas calculator, you must realize that your code has error-handling capabilities, it adds decimal seperators according to the German style, and it adds the ability to output the Euro sign to the screen. As you add more features, your code is naturally expected to get bigger, and once again, there is nothing that I can see in your code that is unnecessary, redundant, or unrequired (I'm not an expert on GetConsoleCP(), GetConsoleOutputCP(), etc..., so I may be wrong here).

**This is my general viewpoint of the code, and any further input for discussion is welcomed.