Summary Files Commits Branches @commit @diff @stats
path: root / src / Television.cpp
diff options
context:
space:
mode:
Commit92630c6d0a1928e6f112013a45b9b681d55c1d63 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-23 14:36:53 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-23 14:36:53 +0300
Files29de5b32bbd3424ffaec04672d028c84a1c6c9dc /src/Television.cpp
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.tar
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.tar.gz
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.zip
Parentd71c054e221013f5d5f24648ded514b475aed3df (diff)
feat: Check for invalid values in widths and heights
1 files changed, 19 insertions, 2 deletions
-rw-r--r--src/Television.cpp21
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);
}