This program shows the use of LOGICAL operators. Keeping in mind that all 3 operators have to be used in one single program!

The problem comes in the part where the user enters '2' for the logical OR operator and then asks for USERNAME and PASSWORD. But it doesn't work out properly. The for-loop used is for the username and password programming to repeat if the values entered are wrong.
The Logical NOT part is written by me yet! But pls help me with the U & P part!




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Demonstrate Logical Operators
#include<iostream.h>
#include<string.h>
void main()
{
	int a = 5, b = 10, c = 15;
	char ch,ch1, pass[20], user[25];
	cout<<"Logical Operators\n"<<" 1. Logical \"OR\" Operator\n"<<" 2. Logical \"AND\" Operator \n"
		<<" 3. Logical \"NOT\" Operator\n"<<"Choose anyone to see its demonstration\n";
	cin>>ch;

		if(ch=='1')
		{
			cout<<"THE LOGICAL \"OR\" OPERATOR\n";
			cout<<" We know that (4 == 4) but (5 != 8). In the logical OR Operator, if any 1 test \n"
				<<"expression evaluates to true then the value of the whole expression turns \n"
				<<"to true i.e, 1 \n";
			cout<<" a = 5, b = 10, c = 15 \n"
			    << "The true expression "<< "a < b || b > c gives " << (a < b || b > c) <<"\n"
				<< "The false expression "<< "a > b || b > c gives "<< (a > b || b > c) << endl;
			cout<<"\nWant to restart??\n";
			cin>>ch1;			
		}

		if(ch=='2')
		{
			cout<<"THE LOGICAL \"AND\" OPERATOR\n";
			cout<<"In this operator, both the test expressions should evaluate to true if\n"
				<<"the whole expression is to be given the value of true.\n"
				<<" If any-1 expression evaluates to false the complete \n"
				<<"expression is given the value of false \n";
			cout<<"This operator can be used for login details.....\n"
				<<"the following program..........\n\n";

			cout<<"Please enter login details\n";
			for(int i = 0; i < 3; i++)
{ 			
			cout<<"\n Enter Username\n";
			cin.getline(user,25);
			cout<<"Enter Password\n";
			cin.getline(pass,20);
			if (((user,25) == 'abd') && ((pass,20) == 'abs'))
			{
				cout<<"\nAccess GRANTED\n";
			}
			else
			{
				cout<<"\nWrong username OR Password\n";	
	                                                               
			}
}
		}
}
Last edited on
your code:

if (((user,25) == 'abd') && ((pass,20) == 'abs'))

this is wrong cos strings must be enclosed int
" "

u will use
' '
only for single char:

1
2
"some string" // string
'a'  // single char 


possible combinations:
1
2
3
4
5
6
7
char* test1 = "some string"
char test2 = 'c'
string test3 = "another string"
const char* test4 = "yet another"
char test5[20] = "string"
char x[] = { 'a', 'b', 'c'}
char* y[] = {"one", "two", "three"}

Last edited on
Topic archived. No new replies allowed.