/*
* @topic T00262 string input and validation using 2 source files
* @brief input and validation functions are defined here
*/
/*
This is our second source file, besides the main file.
In this file we DEFINE functions that were DECLARED in
our header file.
*/
// Include our own header file
#include "user_input.h"
// function to validate user input
bool validate_user_input( std::string str )
{
// make sure that str is made of only '0' and '1' characters
int idx = 0;
int size = str.length();
for ( ; idx < size; ++idx ) {
// for every character in the string
char ch = str[ idx ]; // get character
if ( ch == '0' ) { // if zero,
continue; // go on
} else if ( ch == '1' ) { // if one,
continue; // go on
} else { // if anything else,
return false; // validation fails
}
}//for
// no characters other than zero or one were found,
return true; // validation succeeds
}
// function to display prompt and get user input
std::string get_user_input( std::string prompt )
{
std::cout << prompt; // display prompt
std::string str; // create string
std::cin >> str; // get user input
return str; // return user input
}