Skip to content

feat: do a main operator with user input#459

Open
LeottaAlberto wants to merge 4 commits into
UNICT-Quality-Development:mainfrom
LeottaAlberto:calculator_LA
Open

feat: do a main operator with user input#459
LeottaAlberto wants to merge 4 commits into
UNICT-Quality-Development:mainfrom
LeottaAlberto:calculator_LA

Conversation

@LeottaAlberto
Copy link
Copy Markdown

No description provided.

@Helias
Copy link
Copy Markdown
Member

Helias commented Nov 4, 2025

codestyle fails

Comment thread exercises/calculator.cpp
float num2 = insertNumber("second");

doOperation(num1, num2);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manca return EXIT_SUCCESS;

Comment thread exercises/calculator.cpp Outdated
if(!isCorrect) std::cout << ERROR_COLOR+("[Insert a valid input] ")+NORMAL_COLOR;
std::cout << "Insert "<< position <<" number: ";
getline(std::cin, insert);
} while(!(isCorrect = checkStringIsNumber(insert)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

questo ciclo do-while sembra poco leggibile, potresti aggiungere parentesi e spaziature al primo if e spezzare la condizione dentro il while nel seguente modo

...
isCorrect = checkStringIsNumber(insert)
} while(!isCorrect)

Comment thread exercises/calculator.cpp Outdated
getline(std::cin, insert);
} while(!(isCorrect = checkStringIsNumber(insert)));

return std::stoi(insert);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potresti usare il namespace std per evitare di scrivere std:: nell'intero file

Comment thread exercises/calculator.cpp Outdated
Comment on lines +56 to +63
bool checkStringIsNumber(std::string in){
if(in.empty()) return false;
if(in.size() > MAX_DIGIT) return false;
for(int i = 0; i < in.size(); i++)
if((in.at(i) < ZERO || in.at(i) > NINE) && in.at(i) != MINUS) return false;

return true;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gli spazi non costano, puoi usarli ;-)

Suggested change
bool checkStringIsNumber(std::string in){
if(in.empty()) return false;
if(in.size() > MAX_DIGIT) return false;
for(int i = 0; i < in.size(); i++)
if((in.at(i) < ZERO || in.at(i) > NINE) && in.at(i) != MINUS) return false;
return true;
}
bool checkStringIsNumber(std::string in){
if (in.empty())
return false;
if (in.size() > MAX_DIGIT)
return false;
for (int i = 0; i < in.size(); i++)
if ((in.at(i) < ZERO || in.at(i) > NINE) && in.at(i) != MINUS)
return false;
return true;
}

Comment thread exercises/calculator.cpp Outdated

bool checkStringIsNumber(string in){
if(in.empty()) return false;
if(in.size() > MAX_DIGIT) return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants