Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- bool isDigit(char c) {
- if( c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' || c == '0' )
- return true;
- return false;
- }
- // Pensata come l'albero sintattico (AST)
- bool isNumberRec(std::string s) {
- if (s.length() == 1 && isDigit(s[0]))
- return true;
- // Number ::= NumberCif | Cif
- std::string cutString = s.substr(0, s.size() - 1);
- return (isNumberRec(cutString) && isDigit(s[s.size() - 1]));
- }
- // Pensata come definizione naturale di numero (ovvero sequenza di cifre una dopo l'altra)
- bool isNumber (std::string s) {
- for(int i = 0; i < s.length(); i++)
- if (!isDigit(s[i]))
- return false;
- return true;
- }
- int main() {
- using namespace std;
- string age;
- cout << "Inserisci eta (tra 0 e 130)";
- cin >> age;
- cout << stoi(age) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement