#include <iostream>
#include <string>
int main() {
int age = 25;
std::string user_role = "user";
int score = 85;
int passing_threshold = 70;
int distinction_threshold = 90;
if (age >= 18 && user_role == "admin") {
// This block will NOT execute because user_role is "user"
std::cout << "Access granted as an admin.\n";
} else {
std::cout << "User is not an admin, or is under 18.\n"; // This prints
}
if (score >= distinction_threshold || score >= passing_threshold) {
// This block WILL execute because score >= passing_threshold (85 >= 70)
std::cout << "Score of " << score << " is passing or better.\n"; // This prints
} else {
std::cout << "Score of " << score << " is failing.\n";
}
user_role = "user"; // Reset role for this example
if (user_role == "admin" || (user_role == "user" && score >= distinction_threshold)) {
// This block will NOT execute:
// user_role is "user", not "admin" (false || ...)
// AND user_role is "user" but score is 85, which is not >= 90 (false && false)
std::cout << "Special access criteria met.\n";
} else {
std::cout << "Special access criteria not met for score " << score << " and role " << user_role << ".\n"; // This prints
}
// A condition where both would work:
score = 95;
if (user_role == "admin" || (user_role == "user" && score >= distinction_threshold)) {
// This block WILL execute:
// user_role is "user", and score is 95 which IS >= 90.
std::cout << "Special access criteria met for score " << score << " and role " << user_role << ".\n"; // This prints
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: