How to trap using while loop.
If the item to be entered is smaller (in value) compared to the last item, the input will be disregarded as it is considered invalid entry.
Here's my code...
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
|
#include<iostream>
using namespace std;
int main()
{
int choice, num, item;
while(1)
{
cout<<"\nEnter your choice\n";
cout<<"1. Insert\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter a number to be inserted : ";
cin>>num;
while(num/10000<=0||num/10000>=10)
{
cout<<"Try again : ";
cin>>num;
}
break;
default:
cout<<"Invalid choice\n";
}
}
}
|
Last edited on
I don't see a queue.
Though
while(num/10000<=0||num/10000>=10)
can be shortened to
while(num<1||num>100001)
Topic archived. No new replies allowed.