please check this code :

#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\n 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) || (frontPad ==0 && rearPad ==0 && door==1) || (frontPad ==0 && rearPad ==1 && door==0) || (frontPad ==1 && rearPad ==1 && door==0))
{cout << "close" << endl;
cin >> frontPad;
cin >> rearPad;
cin >> door;
}

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

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

Recommended Answers

All 7 Replies

>>please check this code :

1. its int main() never void main()

2. What exactly do you want us to check?

if you enter 0 or 1 for the three sensors frontPad, rearPad, and door,
it shows the first or two results then it terminates
how could I keep it going where when I enter the input, it won't terminate?

thnx

what is the difference between int main () or void

The difference between int main() and void main() is that the first one is allowed in C++ and the second isn't.

You're going to say "But my compiler accepts it!"

And I'm going to reply "So? Compilers often accept code that's not valid. This fact doesn't make the code valid."

commented: Yes :) +36

if you enter 0 or 1 for the three sensors frontPad, rearPad, and door,
it shows the first or two results then it terminates
how could I keep it going where when I enter the input, it won't terminate?

thnx

Put the code in a loop.

how?
I tried to put it in a while loop but couldn't

how?
I tried to put it in a while loop but couldn't

what is the termination condition?(you have to terminate at some point)

if there is none, you can ask the user "Do you want to continue?" and make it the termination condition.
sample method:
do
{
//get input
//process input
//give output
//ask for "choice"
}while(choice is favorable);

Vinayak

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.