I set a limit for the code using if but it doesnt work

#include <iostream>


using namespace std;

main(){
int num, ones, tens, hundreds, thousands;

a:
cout<<"Enter a digit from 1-3000: ";
cin>>num;
if (1<=num<=3000)
{
thousands=(num/1000)%10;
hundreds=((num/100)%100)%10;
tens=(num/10)%10;
ones=num%10;





switch(thousands){

case 1:
cout<<"One Thousand ";
break;
case 2:
cout<<"Two Thousand ";
break;
case 3:
cout<<"Three Thousand ";
break;
}

switch (hundreds){
case 1:
cout<<"One Hundred ";
break;
case 2:
cout<<"Two Hundred ";
break;
case 3:
cout<<"Three Hundred ";
break;
case 4:
cout<<"Four Hundred ";
break;
case 5:
cout<<"Five Hundred ";
break;
case 6:
cout<<"Six Hundred ";
break;
case 7:
cout<<"Seven Hundred ";
break;
case 8:
cout<<"Eight Hundred ";
break;
case 9:
cout<<"Nine Hundred ";
break;
}



switch (tens){

case 1:
switch (ones)
{



case 1:
cout<<"eleven ";

goto b;
break;
case 2:
cout<<"twelve ";
goto b;
break;


case 3:
cout<<"thirteen ";
goto b;
break;
case 4:
cout<<"Fourteen ";
goto b;
break;
case 5:
cout<<"Fifteen ";
goto b;
break;
case 6:
cout<<"Sixteen ";
goto b;
break;
case 7:
cout<<"Seventeen ";
goto b;
break;
case 8:
cout<<"Eighteen ";
goto b;
break;
case 9:
cout<<"Nineteen ";
goto b;
break;
}
case 2:

cout<<"Twenty ";
break;
case 3:
cout<<"Thirty ";
break;
case 4:
cout<<"Fourty ";
break;
case 5:
cout<<"Fifty ";
break;
case 6:
cout<<"Sixty ";
break;
case 7:
cout<<"Seventy ";
break;
case 8:
cout<<"Eighty ";
break;
case 9:
cout<<"Ninety ";
break;
}

switch (ones){
case 1:
cout<<"One ";
break;
case 2:
cout<<"Two ";
break;
case 3:
cout<<"Three ";
break;
case 4:
cout<<"Four ";
break;
case 5:
cout<<"Five ";
break;
case 6:
cout<<"Six ";
break;
case 7:
cout<<"Seven ";
break;
case 8:
cout<<"Eight ";
break;
case 9:
cout<<"Nine ";
break;
}

b:

return 0;


}

else
{
cout<<"Invalid/Over the Limit"<<endl;
cout<<"PLS TRY AGAIN"<<endl;
goto a;

}
}




if (1<=num<=3000)


is that code isnt really work for the code???


You need to write
if ( 1 <= num && num <= 3000 )


Also, please use [code][/code] tags when posting code.
copy that!

tnx
Topic archived. No new replies allowed.