/****************************************************************************** * This program demonstrates how to prompt the user for input. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #include "Utils.hpp" #include #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace std; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); try { int favoriteInt; long favoriteLong; double favoriteDouble; wstring favoriteIntInput; favoriteIntInput = Utils::prompt(L"What is your favorite small integer? "); favoriteInt = stoi(favoriteIntInput); wstring favoriteLongInput; favoriteLongInput = Utils::prompt(L"What is your favorite large integer? "); favoriteLong = stol(favoriteLongInput); wstring favoriteDoubleInput; favoriteDoubleInput = Utils::prompt(L"What is your favorite floating point? "); favoriteDouble = stod(favoriteDoubleInput); double const sum = favoriteInt + favoriteLong + favoriteDouble; wcout << fmt::format(L"All together they add up to {0:f}!", sum) << endl; } catch (invalid_argument ex) { wcout << L"Bad input! " + Utils::exceptionMessage(ex) << endl; } catch (exception ex) { wcout << L"Don't know what went wrong!" << endl; } return 0; }