Recap - Validation Function
Part of the Fundamentals section of Coddy's C++ journey — lesson 56 of 74.
Challenge
EasyWrite a function named is_valid that gets two string arguments, username and password.
The function will return true if the username and password are valid in the system, otherwise false.
Our system contains only two valid usernames - "admin" and "user".
The valid password for username "user" is "qwerty".
For username "admin" any password is valid!
Try it yourself
#include <iostream>
#include <string>
bool is_valid(std::string username, std::string password) {
// Write your code below
}
int main() {
std::string user, pass;
std::cin >> user;
std::cin >> pass;
bool res = is_valid(user, pass);
std::cout << (res ? "true" : "false");
return 0;
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison10Functions
Declare a FunctionParametersReturn TypesFunction OverloadingRecap - Sigma FunctionRecap - Validation FunctionVoid Functions3Variables Part 2
Type DeclarationNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementConditional OperatorRecap - If ElseNested If - Else