#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double x,i=10000000;
int j=0;
unsigned int quotient,remainder;
bool beginFlag=0,zeroFlag=0;
cout<<"请输入预转换数额(小于1亿):"<<endl;
cin>>x;
while(x>=100000000)
{
if(j>=2)
{
cout<<"你的错误输入已达3次,你无权再输入!"<<endl;
return 0;
}
cout<<"你输入的金额超出转换范围,请重新输入!"<<endl;
cout<<"请输入预转换数额(小于1亿):";
cin>>x;
j++;
}
if(x<=0)
{
cout<<"零元整"<<endl;
return 0;
}
x=floor(x*100 +0.5)/100; //小数点后2位四舍五入
while (i>0.001)
{
if (i>0.9)
quotient=(unsigned int)floor(x/i);
else
{
if (i>=0.099)
quotient=(unsigned int)floor(x*10);
else
quotient=(unsigned int)floor(x*100);
}
remainder=quotient%10;
if (remainder!=0)
beginFlag=1;
if ((zeroFlag==1) && (beginFlag==1) && (remainder>0))
cout<<"零";
switch (remainder) //输出大写数字
{
case 0:
break;
case 1:
cout<<"壹";
break;
case 2:
cout<<"贰";
break;
case 3:
cout<<"叁";
break;
case 4:
cout<<"肆";
break;
case 5:
cout<<"伍";
break;
case 6:
cout<<"陆";
break;
case 7:
cout<<"柒";
break;
case 8:
cout<<"捌";
break;
case 9:
cout<<"玖";
break;
}
if (remainder>0)
zeroFlag=0;
else if (beginFlag==1)
zeroFlag=1;
if (beginFlag==1) //输出单位
{
if ((i==10000000) && (remainder>0))
cout<<"仟";
if ((i==1000000) && (remainder>0))
cout<<"佰";
if ((i==100000) && (remainder>0))
cout<<"十";
if (i==10000)
cout<<"万";
if ((i==1000) && (remainder>0))
cout<<"仟";
if ((i==100) && (remainder>0))
cout<<"佰";
if ((i==10) && (remainder>0))
cout<<"十";
/*if (i==1)
cout<<"元";
if ((i>=0.09) && (i<1) && (remainder>0))
cout<<"角";
if ((i>=0.009) && (i<0.1) && (remainder>0))
cout<<"分";
*/
}
i=i/10;
}
cout<<"整"<<endl;
}
人民币小写转换成大写
最新推荐文章于 2018-07-01 21:58:31 发布