{"id":28717393,"url":"https://github.com/mpluxery/basic-cpp-age-checker","last_synced_at":"2025-06-15T03:15:35.105Z","repository":{"id":296789214,"uuid":"976106574","full_name":"mpluxery/Basic-CPP-age-checker","owner":"mpluxery","description":"Simple C++ console application that prompts the user to enter their age, validates that the input is a number between 1 and 99; otherwise, it displays an error message and re-prompts until a valid age is entered.","archived":false,"fork":false,"pushed_at":"2025-06-02T02:23:18.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T12:08:24.162Z","etag":null,"topics":["beginner-code","beginner-friendly","c-plus-plus","cpp","else-if","input-validation","tutorial"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mpluxery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-01T14:02:40.000Z","updated_at":"2025-06-02T02:25:09.000Z","dependencies_parsed_at":"2025-06-02T12:08:28.037Z","dependency_job_id":"82a32544-8d77-4963-bf16-af5c5fa517b8","html_url":"https://github.com/mpluxery/Basic-CPP-age-checker","commit_stats":null,"previous_names":["mpluxery/basic-cpp-age-checker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mpluxery/Basic-CPP-age-checker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpluxery%2FBasic-CPP-age-checker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpluxery%2FBasic-CPP-age-checker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpluxery%2FBasic-CPP-age-checker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpluxery%2FBasic-CPP-age-checker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpluxery","download_url":"https://codeload.github.com/mpluxery/Basic-CPP-age-checker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpluxery%2FBasic-CPP-age-checker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259914924,"owners_count":22931334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beginner-code","beginner-friendly","c-plus-plus","cpp","else-if","input-validation","tutorial"],"created_at":"2025-06-15T03:15:34.099Z","updated_at":"2025-06-15T03:15:35.047Z","avatar_url":"https://github.com/mpluxery.png","language":"C++","readme":"# Valid Age Checker in C++\n\n## Description\nThis is a simple C++ program that prompts the user to enter their age and validates that the input is a numeric value between 1 and 99, with no extra characters. If the input does not meet these criteria, the program displays an error message and asks again until a valid age is entered. Once a valid number is provided, it outputs a confirmation message including the entered age.\n\n## Installation and Build\n1. Make sure you have a C++ compiler installed (for example, g++).  \n2. Save the source code below into a file named `io.cpp`.  \n3. Open a terminal in the same directory as `io.cpp` and run:\n\n  g++ io.cpp -o valid_age\n   \nUsage\nAfter a successful build, execute the program by typing:\n\n\n./valid_age\nWhen prompted:\n\nEnter Age:\ntype a number between 1 and 99 and press Enter.\n\nIf the input is invalid (non-numeric characters, numbers outside 1–99, or extra characters), the program will print:\n\nbe for real!\nand prompt again.\n\nOnce a valid age is entered, you will see:\n\nYou are \u003cage\u003e years old, seems legit!\nFor example:\n\nYou are 25 years old, seems legit!\nSource Code (io.cpp)\n\n#include \u003ciostream\u003e\n#include \u003csstream\u003e\n#include \u003cstring\u003e\n\nint main()\n{\n    int age = 0;\n    bool valid = false;\n    char null = '\\0';\n\n    while (!valid)\n    {\n        std::cout \u003c\u003c \"Enter Age: \";\n\n        std::string line;\n        std::getline(std::cin, line);\n\n        std::stringstream is(line);\n\n        // Validate:  \n        // 1. Attempt to extract an integer into `age`.  \n        // 2. Check for any extra characters after the number.  \n        // 3. Ensure age is between 1 and 99 (inclusive).\n        if (!(is \u003e\u003e age) || (is \u003e\u003e std::ws \u0026\u0026 is.get(null)) || age \u003e= 100 || age \u003c= 0)\n            std::cout \u003c\u003c \"be for real!\" \u003c\u003c std::endl;\n        else\n            valid = true;\n    }\n\n    std::cout \u003c\u003c \"You are \" \u003c\u003c age \u003c\u003c \" years old, seems legit!\" \u003c\u003c std::endl;\n    return 0;\n}\nHow It Works\nVariables\n\nage (int): Stores the user’s age.\n\nvalid (bool): Becomes true once a valid age is entered.\n\nnull (char): Used to detect any extra character after the numeric input.\n\nInput Loop\n\nThe while (!valid) loop repeatedly prompts the user to enter their age.\n\nstd::getline(std::cin, line) reads the entire line of input as a string.\n\nString Parsing and Validation\n\nA std::stringstream named is is initialized with the input line.\n\nis \u003e\u003e age attempts to parse an integer; if this fails, the input is not a valid number.\n\n(is \u003e\u003e std::ws \u0026\u0026 is.get(null)) checks for any non-whitespace characters remaining in the stream after parsing the integer (for example, letters or extra digits). If it finds anything, the input is considered invalid.\n\nThe conditions age \u003e= 100 || age \u003c= 0 ensure the age is within the range [1, 99].\n\nIf any validation step fails, the program prints “be for real!” and repeats the prompt.\n\nSuccessful Input\n\nWhen a valid age is provided, the loop exits and the program prints:\n\n\nYou are \u003cage\u003e years old, seems legit!\nExit\n\nThe program returns 0 to indicate successful execution.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpluxery%2Fbasic-cpp-age-checker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpluxery%2Fbasic-cpp-age-checker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpluxery%2Fbasic-cpp-age-checker/lists"}