From 3b8f1817d2e89f8a06f63537c00166852b4ad8a0 Mon Sep 17 00:00:00 2001 From: AkinshinaDA Date: Thu, 17 Apr 2025 15:51:11 +0300 Subject: [PATCH] =?UTF-8?q?Code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80?= =?UTF-8?q?=20prompt=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 5f70b72..5cd9e15 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "histogram.h" #include "text.h" #include "svg.h" @@ -11,22 +12,32 @@ struct Input { size_t bin_count{}; }; Input -input_data(istream& in){ +input_data(istream& in, bool prompt){ + cerr << "Do you need hints? Type 0 for no, 1 for yes: "; + int ans; + int state = 0; + while (state ==0){ + in >> ans; + if (ans==1) {prompt = true; state=1;} + else if (ans==0) {prompt = false; state=1;} + else cerr << "Invalid data. Please type only 0 or 1: "; + } size_t number_count; - cerr << "Enter number count: "; + if (prompt == true) cerr << "Enter number count: "; in >> number_count; Input input; input.numbers.resize(number_count); - cerr << "Enter numbers: "; + if (prompt == true) cerr << "Enter numbers: "; for (size_t i = 0; i < number_count; i++){ in >> input.numbers[i]; } - cerr << "Enter bin count: "; + if (prompt == true) cerr << "Enter bin count: "; in >> input.bin_count; return input; } int main(){ - auto in = input_data(cin); + bool prompt; + auto in = input_data(cin, prompt); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins); }