Skip to content

Commit a72a67c

Browse files
committed
style(calculator.cpp): improve readability and naming consistency
1 parent 4da429a commit a72a67c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

exercises/calculator.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
using namespace std;
1818

19-
const string ERROR_COLOR = "\033[31m";
20-
const string NORMAL_COLOR = "\033[0m";
19+
const string COLOR_ERROR = "\033[31m";
20+
const string COLOR_RESET = "\033[0m";
2121

22-
const int ZERO = 48;
23-
const int NINE = 57;
24-
const int MAX_DIGIT = 10;
25-
const int MINUS = 45;
22+
const int ASCII_ZERO = 48;
23+
const int ASCII_NINE = 57;
24+
const int ASCII_MINUS = 45;
25+
const int MAX_DIGITS = 10;
2626

2727
int insertNumber(string position);
2828
bool checkStringIsNumber(string in);
@@ -48,7 +48,7 @@ int insertNumber(string position){
4848
string insert;
4949
bool isCorrect = true;
5050
do {
51-
if(!isCorrect) cout << ERROR_COLOR+("[Insert a valid input] ")+NORMAL_COLOR;
51+
if(!isCorrect) cout << COLOR_ERROR+("[Insert a valid input] ")+COLOR_RESET;
5252
cout << "Insert "<< position <<" number: ";
5353
getline(cin, insert);
5454

@@ -59,12 +59,15 @@ int insertNumber(string position){
5959
}
6060

6161
bool checkStringIsNumber(string in){
62-
if(in.empty()) return false;
63-
if(in.size() > MAX_DIGIT) return false;
62+
if(in.empty())
63+
return false;
64+
if(in.size() > MAX_DIGITS)
65+
return false;
6466

6567
for(int i = 0; i < in.size(); i++)
66-
if((in.at(i) < ZERO || in.at(i) > NINE) && in.at(i) != MINUS)
67-
return false;
68+
if((in.at(i) < ASCII_ZERO || in.at(i) > ASCII_NINE))
69+
if(in.at(i) != ASCII_MINUS)
70+
return false;
6871

6972
return true;
7073
}

0 commit comments

Comments
 (0)