I have to create a program that has validation in it, The programme asks the user for the weight of a package, and sets the cost appropriately, I have a do in place do that if the user types in a minus number it gives them an error.
do{
clrscr();
cout<<"\n Enter the weight of the package to be delivered ";
cin>>weight;
if(weight<0)
{
cout<<"\n Error! ENTER A POSITIVE NUMBER ONLY";
}
if(weight<=1)
{
cost=2.50;
}
if (weight >1 && weight <=10)
{
cost=7.50;
}
if (weight>=10)
{
cost=10.00;
}
} while(weight<0) ;
But how to I stop the user entering a letter when it should be numbers only?
Thanks In Advance
do{
clrscr();
cout<<"\n Enter the weight of the package to be delivered ";
cin>>weight;
if(weight<0)
{
cout<<"\n Error! ENTER A POSITIVE NUMBER ONLY";
}
if(weight<=1)
{
cost=2.50;
}
if (weight >1 && weight <=10)
{
cost=7.50;
}
if (weight>=10)
{
cost=10.00;
}
} while(weight<0) ;
But how to I stop the user entering a letter when it should be numbers only?
Thanks In Advance
Comment