C++ examples for Operator:Logical Operator
Operator | Description |
---|---|
&& | Logical AND |
|| | Logical OR |
! | Logical negation (NOT) |
Combining logical operators for loan approval
#include <iostream> int main() {// w w w . ja va 2 s.c om int age {}; // Age of the prospective borrower int income {}; // Income of the prospective borrower int balance {}; // Current bank balance std::cout << "Please enter your age in years: "; std::cin >> age; std::cout << "Please enter your annual income in dollars: "; std::cin >> income; std::cout << "What is your current account balance in dollars: "; std::cin >> balance; if(age >= 21 && (income > 25000 || balance > 100000)) { int loan {}; // Stores maximum loan amount if(2*income < balance/2) { loan = 2*income; } else { loan = balance/2; } std::cout << "\nYou can borrow up to $" << loan << std::endl; } else { // No loan for you... std::cout << "\nUnfortunately, you don't qualify for a loan." << std::endl; } }