From cf209e4a49fabde8c9bca9d47af1725fb5ee8c34 Mon Sep 17 00:00:00 2001 From: Joseph Williams Date: Thu, 13 Oct 2022 16:10:03 -0700 Subject: Completed step 2 (Print what the user entered for width and height). Continued work on emotional simulation algorithm (I made it print some overly cheerful messages). --- BlankConsoleLab/BlankConsoleLab.cpp | 44 ++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 8ca8157..ff2bf87 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -1,4 +1,7 @@ #include +#include //used for converting things to strings +#include //feeding my crippling addiction to overengineering everything +#include //^^^ #include //colored couts go brrrr :) using namespace std; @@ -12,27 +15,39 @@ const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //linebreak (bool): Whether to end the line after printing. Optional, defaults to true. void colorPrint(string text, int color = 15, bool linebreak = true, HANDLE console = hConsole) { - if (linebreak) //Add a line break to the end of the text unless told not to - { - text += "\n"; - } SetConsoleTextAttribute(console, color); //Use black magic (native OS commands) to change the color of any text we print. cout << text; SetConsoleTextAttribute(console, 15); //Use more black magic to set the color back to white so that we don't start randomly printing other colors. + if (linebreak) //Add a line break to the end of the text unless told not to + { + cout << endl; + } +} +void multiColorPrint(vector > text, HANDLE console = hConsole) +{ + string fragmentText; + int fragmentColor; + bool fragmentBreak; + for (auto i : text) { + tie(fragmentText, fragmentColor, fragmentBreak) = i; + colorPrint(fragmentText, fragmentColor, fragmentBreak, console); + } } //Super messy and really just here because if you're reusing more than one line, you're doing something wrong. int getWidthOrHeight(string d) { int input; + vector > text; + text.push_back(make_tuple("Please enter the ", 15, false)); + text.push_back(make_tuple(d, 13, false)); + text.push_back(make_tuple(" of your kite in ", 15, false)); + text.push_back(make_tuple("cm", 13, false)); + text.push_back(make_tuple(": ", 15, false)); while (true) { - cout << "Please enter the "; - colorPrint(d, 5, false); - cout << " of your kite in "; - colorPrint("cm", 5, false); - cout << ": "; + multiColorPrint(text); if (cin >> input) //This feels so wrong but it does in fact work. { break; @@ -47,12 +62,15 @@ int getWidthOrHeight(string d) int main() { int width, height; - bool haveWidth = false, haveHeight = false; //If the user has entered a valid width and height yet. Used for looping. - colorPrint("Welcome to Kite Calculator!\n", 9); + colorPrint("Welcome to Kite Calculator!\n", 11); - colorPrint("Let's start with getting the dimensions of your kite!", 11); + colorPrint("Let's start with getting the dimensions of your kite!", 9); width = getWidthOrHeight("width"); height = getWidthOrHeight("height"); - + cout << endl; + //Tell the user what they just entered, because...reasons. + colorPrint("Great job!", 10); + multiColorPrint(vector > {make_tuple("Your kite is ", 15, false), make_tuple(to_string(width) + "cm", 13, false), make_tuple(" wide and ", 15, false), make_tuple(to_string(height) + "cm", 13, false), make_tuple(" high.", 15, true), }); + colorPrint("I'm sure it's beautiful!", 11); } \ No newline at end of file -- cgit v1.2.3