I have another question regarding activating of an automatic door:
three sensors front pad, rear pad, and door; they determine weather the door is activated or not.
front pad=0 empty
front pad=1 occupied

rear pad=0 empty
rear pad=1 occupied

door=0 closed
door=1 open

there are situations when the door is activated or not :

front pad rear pad door activation
0 0 0 no
0 0 1 no
0 1 0 no
1 1 0 no
0 1 1 yes
1 0 0 yes
1 0 1 yes
1 1 1 yes

I wrote the code but it is not outputting the result

#include <iostream>// requires for keyboard and screen I/O
#include <conio.h>

using namespace std;

void main ()

{
int frontPad=0;
int rearPad=0;
int door=0;
cout << "Welcome" << endl;
cout << " Enter either 0 or 1 for state of the Front Pad,\n Rear Pad,\n and the Door" << endl;
cout << " separated by a blank" << endl;
cin >> frontPad;
cin >> rearPad;
cin >> door;

if ((frontPad ==0 && rearPad==0 && door==0) || (rearPad ==0 && rearPad ==0 && door==1) || (rearPad ==0 && rearPad ==1 && door==0) || (rearPad ==1 && rearPad ==1 && door==0))
{cout << "close" << endl;
cin >> frontPad;
cin >> rearPad;
cin >> door;
}

else (rearPad ==0 && rearPad ==1 && door==1) || (rearPad ==1 && rearPad ==0 && door==0) || (rearPad ==1 && rearPad ==0 && door==1) || (rearPad ==1 && rearPad ==1 && door==1))
cout << "open" << endl;
cin >> frontPad;
cin >> rearPad;
cin >> door;


	getch(); // holding the screen
} // end main

Look at lines 19 and 26. Many of the conditions require that the rearPad value have two distinct values; rearPad == 0 && rearPad == 1 will always return false, for example. Some of the references to the rearPad variable should be replaced with frontPad; this should give the desired result.

As an aside, the C standard says your main procedure should be int main instead of void main, and return zero at the end. This is to tell the operating system that your program succeeds; otherwise, the OS thinks the program did not execute properly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.