C语言以文件形式编写人民币大小写的转化
1个回答
2013-10-22
展开全部
#include <iostream.h>
#include <math.h>
void main()
{ double x,i=10000000;
int j=0;
unsigned int quotient,remainder;
bool beginFlag=0,zeroFlag=0;
cout<<"请输入预转换数额(小于1亿):";
cin>>x;
while (x>=100000000 )
{
if (j>=2)
{
cout<<"你的错误输入已达3次,你无权再输入!"<<endl;
return;
}
cout<<"你输入的金额超出转换范围,请重新输入!"<<endl;
cout<<"请输入预转换数额(小于1亿):";
cin>>x;
j++;
}
if (x<=0)
{
cout<<"零元整"<<endl;
return;
} 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) && (i>1000) && (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;
}
#include <math.h>
void main()
{ double x,i=10000000;
int j=0;
unsigned int quotient,remainder;
bool beginFlag=0,zeroFlag=0;
cout<<"请输入预转换数额(小于1亿):";
cin>>x;
while (x>=100000000 )
{
if (j>=2)
{
cout<<"你的错误输入已达3次,你无权再输入!"<<endl;
return;
}
cout<<"你输入的金额超出转换范围,请重新输入!"<<endl;
cout<<"请输入预转换数额(小于1亿):";
cin>>x;
j++;
}
if (x<=0)
{
cout<<"零元整"<<endl;
return;
} 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) && (i>1000) && (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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询