diff options
feat: Check for invalid values in widths and heights
1 files changed, 19 insertions, 2 deletions
| -rw-r--r-- | src/Television.cpp | 21 |
diff --git a/src/Television.cpp b/src/Television.cpp index 35f1d46..b682211 100644 --- a/src/Television.cpp +++ b/src/Television.cpp @@ -1,5 +1,6 @@ #include "Television.h" #include "cli.hpp" +#include <iostream> Television::Television(mm width, mm height) : Screen(width, height) { } @@ -7,10 +8,26 @@ Television::~Television() { } Television* Television::fromCommandLine() { mm iwidth = 0; - cli::readUserInput(iwidth, "Enter width (in mm): ", "Invalid width, try again!"); + do { + cli::readUserInput(iwidth, "Enter width (in mm): ", "Invalid width, try again!"); + + if (iwidth == 0) { + std::cerr << "Width cannot be zero! Try again!" << std::endl; + continue; + } + break; + } while (true); mm iheight = 0; - cli::readUserInput(iheight, "Enter height (in mm): ", "Invalid height, try again!"); + do { + cli::readUserInput(iheight, "Enter height (in mm): ", "Invalid height, try again!"); + if (iheight == 0) { + std::cerr << "Height cannot be zero! Try again!" << std::endl; + continue; + } + break; + } + while (true); return new Television(iwidth, iheight); } |