44#include < string>
55#include < map>
66
7+ using namespace std ;
8+
79const int ZERO = 48 ;
810const int NINE = 57 ;
911const int MAX_NUMBER = 10 ;
1012const int MINUS = 45 ;
1113
12- const std:: string ERROR_COLOR = " \033 [31m" ;
13- const std:: string NORMAL_COLOR = " \033 [0m" ;
14+ const string ERROR_COLOR = " \033 [31m" ;
15+ const string NORMAL_COLOR = " \033 [0m" ;
1416
1517int insertNumber ();
16- bool checkStringIsNumber (std:: string in);
18+ bool checkStringIsNumber (string in);
1719
1820int main (){
1921 int month = insertNumber ();
20- std:: map<int , std:: string> calendary = {
22+ map<int , string> calendary = {
2123 {1 , " 31" },
2224 {2 , " 28/29" },
2325 {3 , " 31" },
@@ -31,25 +33,35 @@ int main(){
3133 {11 , " 30" },
3234 {12 , " 31" },
3335 };
34- std:: cout << calendary[month] << " days" ;
36+ cout << calendary[month] << " days" ;
3537 return 0 ;
3638}
3739
3840int insertNumber (){
39- std:: string insert;
41+ string insert;
4042 bool isCorrect = true ;
43+
4144 do {
42- if (!isCorrect) std::cout << ERROR_COLOR+(" [Insert a valid input] " )+NORMAL_COLOR;
43- std::cout << " Insert Mounth: " ;
44- getline (std::cin, insert);
45- } while (!(isCorrect = checkStringIsNumber (insert)));
46- return std::stoi (insert);
45+ if (!isCorrect) cout << ERROR_COLOR+(" [Insert a valid input] " )+NORMAL_COLOR;
46+
47+ cout << " Insert Mounth: " ;
48+ getline (cin, insert);
49+
50+ isCorrect = checkStringIsNumber (insert);
51+ } while (!isCorrect);
52+
53+ return stoi (insert);
4754}
4855
49- bool checkStringIsNumber (std::string in){
50- if (in.empty ()) return false ;
56+ bool checkStringIsNumber (string in){
57+ if (in.empty ())
58+ return false ;
59+
5160 for (int i = 0 ; i < in.size (); i++)
52- if ((in.at (i) < ZERO || in.at (i) > NINE) && in.at (i) != MINUS) return false ;
61+ if ((in.at (i) < ZERO || in.at (i) > NINE) && in.at (i) != MINUS)
62+ return false ;
63+
5364 if (stoi (in) > MAX_NUMBER) return false ;
65+
5466 return true ;
5567}
0 commit comments