New answers tagged

2

Generally good. A couple of weaknesses: We probably want to exit if std::getline() returns a failed stream. We might want to do the same for an empty input. Personally, I'd probably prefer to accept the message as command arguments, rather than reading standard input. On platforms without clear or where clear doesn't accept -x, we'll likely get an ...


0

fg_black="\e[30m" fg_white="\e[37m" bg_red="\e[41m" bg_blue="\e[44m" bg_purple="\e[45m" These control codes are terminal-specific. Prefer to use tput to create the appropriate codes for the actual $TERM being used.


0

Make a string str full of spaces with the length of variable a: printf -v str "%*s" ${#a} " " # or str="${a//[^ ]/ }*" I don't like the feature that you can have 2 different kind of parameters (string or function name) for setting a color. In the future you might want to enhance your function (make it split up the sting to a fg ...


2

This would be my feedback : #include <iostream> // #include <ctime> // removed this is not needed when using <random> header #include <random> // prefered random generator for C++, srand is more of a C left over. #include <string> #include <vector> //-----------------------------------------------------------------------...


5

Looks pretty good and kudos for not having using namespace std; Here is some nitpicking. Your indentation is all over the place, here you have an extra tab: if (secret_word.find(guess) != std::string::npos) { for (int i = 0; i < guess_word.length(); ++i) And here you use a different convention: } else { ++try_no; } Create your ...


3

This code is WET (wrote everything twice) and hard to extend/reuse. What if you want to ask, say, 10 questions? How about 100? Following the original design would likely create a pyramid of doom. We can DRY it out and flatten the pyramid with promises and a loop: const readline = require("readline"); const rl = readline.createInterface({ input: ...


0

mainMenu.AppendLine("[1] Yes"); This part is in need of some improvements. AppendLine is not a descriptive enough name. AddOption, AddChoice, AddMenuItem, ... would be better. One thing I also suspect is that you probably haven't though through the actual selection logic yet. You've encoded the input values (1, 2) into the string, which is ...


1

Here are my observations: UIMenu Try to use consistent naming Your current naming: Title, MenuRows, AppendLine Suggested naming #1: Title, Items, AddItem Suggested naming #2: MenuHeader, MenuRows, AddMenuRow You don't need the parameterless ctor You can simply initialize the MenuRows when you declare it public List<string> MenuRows { get; } = new ...


Top 50 recent answers are included