Hi Dave,
I didn't copy the whole program, only the loop, so you're spot on, it doesn't do much on its own!
Try this:
Code:
# include<iostream>
using namespace std;
int main()
{
int a = 0 ;
do
{
cout<<"\n\n\n";
cout<<"\t Please choose 1 item.\n\n";
cout<<"\t 1 : one\n\n";
cout<<"\t 2 : two\n\n";
cout<<"\t 3 : three\n";
cout<<"\t -------------\n";
cout<<"\t Choice : ";
cin>>a;
} while (a !=1 && a != 2 && a != 3);
if (a == 1)
{
cout << "You pressed: " << a;
}
else if (a == 2)
{
cout << "You pressed: " << a;
}
else if (a == 3)
{
cout << "You pressed: " << a;
}
}
and substitute the while condition with these:
Code:
while (!(a == 1 || a == 2 || a == 3)); // Similar to what you did. If any are TRUE, the ! makes them FALSE
or
Code:
while (!(a >= 1 && a <= 3)); // Anything greater or equal to 1 AND less than or equal to 3.
or
Code:
while (!(a > 0 && a < 4)); // Anything greater than 0 AND less than 4.
or (this makes most sense to me)
Code:
while (a < 1 || a > 3); // Anything less than 1 OR anything greater than 3.
There are a number of ways to achieve the same thing. I'll leave it up to the experts here to say which would be considered best practice.
I hope this gives you a few new ideas