Skip to content

richelbilderbeek/correct_cpp_is_even

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

correct_cpp_is_even

Branch Travis CI Codecov
master Build Status codecov.io

Correct C++ chapter 'is even'.

Goals

  • First use of std::regex

Prerequisites

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]