Table of Contents
Back Button
Back to Chapter
C++ Setting Up
C++ Introduction
No items found.
C++ Basics
No items found.
C++ Control Statements
No items found.
C++ Logical Operators
No items found.
C++ Procedural Programming
No items found.
C++ Structural Programming
No items found.
C++ Implementation of OOPS
No items found.
C++ Arrays and Vectors
No items found.
C++ Error Handling
No items found.
C++ File Handling
No items found.

C++ Logical Operators Exercise

Now based on what we have learnt let us try to create a login page.

The login page should ask the user to enter a username, password, and code if the username and either the password or code are correct to provide access.


password = admin123

username = admin



#include using namespace std; int main () { string userName; string userPassword; int code; int loginAttempt = 0; while (loginAttempt < 5)//restricting number of time user enters wrong credentials { cout << "Please enter your user name: "; cin >> userName; cout << "Please enter your user password: "; cin >> userPassword; cout << "enter your code:"; cin >> code; // to check if username and password is correct if (userName == "ADMIN") && (userPassword == "admin123" || code==1234) { cout << "Welcome ADMIN!\n"; break; } else { cout<<"try again!!"<
Output: Please enter your user name: ADMIN Please enter your user password: sakmd enter your code:1234 Welcome ADMIN! Thank you for logging in.
Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?