diff options
| author | Joseph Williams <[email protected]> | 2022-10-13 16:10:03 -0700 |
|---|---|---|
| committer | Joseph Williams <[email protected]> | 2022-10-13 16:10:03 -0700 |
| commit | cf209e4a49fabde8c9bca9d47af1725fb5ee8c34 (patch) | |
| tree | 585a3b997b21911d411cd13f440946e5ad99481e /BlankConsoleLab | |
| parent | completed step 1 (ask user for width and height) (diff) | |
| download | cst116-lab1-allthenamesaretaken3141-cf209e4a49fabde8c9bca9d47af1725fb5ee8c34.tar.xz cst116-lab1-allthenamesaretaken3141-cf209e4a49fabde8c9bca9d47af1725fb5ee8c34.zip | |
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).
Diffstat (limited to 'BlankConsoleLab')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 44 |
1 files 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 <iostream> +#include <string> //used for converting things to strings +#include <vector> //feeding my crippling addiction to overengineering everything +#include <tuple> //^^^ #include <windows.h> //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<tuple<string, int, bool> > 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<tuple< string, int, bool> > 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<tuple< string, int, bool> > {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 |