MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / validate_input

Function validate_input

Exercises/Modules/Chapter 08/Soln8_01.cpp:33–44  ·  view source on GitHub ↗

Reads an integer that is between lower and upper inclusive

Source from the content-addressed store, hash-verified

31
32// Reads an integer that is between lower and upper inclusive
33int validate_input(int lower, int upper, const std::string& description)
34{
35 int data {};
36 std::cout << std::format("Please enter {} from {} to {}: ", description, lower, upper);
37 std::cin >> data;
38 while (data < lower || data > upper)
39 {
40 std::cout << "Invalid entry; please re-enter " << description << ": ";
41 std::cin >> data;
42 }
43 return data;
44}
45
46// Reads the year
47int year()

Callers 3

yearFunction · 0.70
monthFunction · 0.70
dateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected