主题:[原创]c++中如何避免输入数据某一位出现非数字符号
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main( )
{
double ds=0,dsh=0,s,j,z,one,two;
char *c="请输入您的基本工资(RMB):";
char *d="你可以计算另外一个税务 (继续按“y”退出按“n”)? ";
char indicator('y');
//总工资=基本工资(j)+1.5倍加班(one)+2倍加班(two)
//实发工资=总工资-个人所得税
cout<<"税务总局偷税漏税专用工具2.0"
<<endl;
while ('y' == indicator)
{
ds=0;
dsh=0;
cout <<c;
cin>>j;
cout <<endl <<"请输入你的1.5倍加班数(h):";
cin>>one;
cout <<endl <<"请输入你的2倍加班数(h):";
cin>>two;
z=j+(j/174)*1.5*one+(j/174)*2*two;
s=z-3500;
//x=j+(j/174)*one+(j/174)*two;
if(s<0)
dsh=z;
else if(s<1500)
{ds=s*0.03;dsh=z-ds;}
else if(s<4500)
{ds=s*0.1-105;dsh=z-ds;}
else if(s<9000)
{ ds=s*0.2-555;dsh=z-ds;}
else if(s<35000)
{ds=s*0.25-1005;dsh=z-ds;}
else if(s<55000)
{ ds=s*0.3-2755;dsh=z-ds;}
else if(s<80000)
{ ds=s*0.35-5505;dsh=z-ds;}
else
{ds=s*0.45-13505;dsh=z-ds;}
cout <<"==================================================\n"
<<"你的基本工资: "<<j<<endl
<<"1.5倍加班加了"<<one<<" 小时"<<endl
<<"2倍加班加了"<<two<<" 小时"<<endl
<<"你总收入是 " <<z <<"元,"<<endl
<<"您应缴个人所得税 "<<ds<<" 元,"<<endl
<<"税后收入是 "<<dsh<<" 元。\n";
cout<<"依法偷税,共享繁荣。谢谢使用!\n"
<<"==================================================\n"
<<d;
cin >> indicator;
}
system("pause");
return 0;
}
如何避免参数j,one,two因输入非数字符号而进入死循环?
using std::cin;
using std::cout;
using std::endl;
int main( )
{
double ds=0,dsh=0,s,j,z,one,two;
char *c="请输入您的基本工资(RMB):";
char *d="你可以计算另外一个税务 (继续按“y”退出按“n”)? ";
char indicator('y');
//总工资=基本工资(j)+1.5倍加班(one)+2倍加班(two)
//实发工资=总工资-个人所得税
cout<<"税务总局偷税漏税专用工具2.0"
<<endl;
while ('y' == indicator)
{
ds=0;
dsh=0;
cout <<c;
cin>>j;
cout <<endl <<"请输入你的1.5倍加班数(h):";
cin>>one;
cout <<endl <<"请输入你的2倍加班数(h):";
cin>>two;
z=j+(j/174)*1.5*one+(j/174)*2*two;
s=z-3500;
//x=j+(j/174)*one+(j/174)*two;
if(s<0)
dsh=z;
else if(s<1500)
{ds=s*0.03;dsh=z-ds;}
else if(s<4500)
{ds=s*0.1-105;dsh=z-ds;}
else if(s<9000)
{ ds=s*0.2-555;dsh=z-ds;}
else if(s<35000)
{ds=s*0.25-1005;dsh=z-ds;}
else if(s<55000)
{ ds=s*0.3-2755;dsh=z-ds;}
else if(s<80000)
{ ds=s*0.35-5505;dsh=z-ds;}
else
{ds=s*0.45-13505;dsh=z-ds;}
cout <<"==================================================\n"
<<"你的基本工资: "<<j<<endl
<<"1.5倍加班加了"<<one<<" 小时"<<endl
<<"2倍加班加了"<<two<<" 小时"<<endl
<<"你总收入是 " <<z <<"元,"<<endl
<<"您应缴个人所得税 "<<ds<<" 元,"<<endl
<<"税后收入是 "<<dsh<<" 元。\n";
cout<<"依法偷税,共享繁荣。谢谢使用!\n"
<<"==================================================\n"
<<d;
cin >> indicator;
}
system("pause");
return 0;
}
如何避免参数j,one,two因输入非数字符号而进入死循环?