Awesome
correct_cpp_is_even
Branch | Travis CI | Codecov |
---|---|---|
master |
Correct C++ chapter 'is even'.
Goals
- First use of std::regex
Prerequisites
- Understand how this course works
- Have written a correct 'is_odd' program
Exercise
Write a command-line interface (CLI) program that determines if its argument is an even number.
If there are more arguments supplied, exit the program.
Call to is_even | Output | Exit status |
---|---|---|
./is_even | Any | 1 |
./is_even 12345678901234567890 | true (with newline) | 0 |
./is_even 12345678901234567891 | false (with newline) | 0 |
./is_even nonsense | Any | 1 |
./is_even 2 1 | Any | 1 |
This is the code you start with:
main(argc, argv)
{
//Your code here
}
- You cannot use std::stoi, as it will not convert
12345678901234567890
to integer - Instead, you should use std::regex
- An even number is a regular expression of one or more digits, that may or may not start with a minus
External links
- [none]