c语言问题,能进来帮助下吗??
怎么输入小写金额数把它换成大写的??比如:1325 要换成壹仟叁佰贰拾伍
#include <stdio.h>
#include <math.h>
void main()
{
doublex,i=10000000;
int j=0;
unsigned int quotient,remainder;
int beginFlag=0, zeroFlag=0;
printf("请输入预转换数额(小于1亿):\n");
scanf("%lf",&x);
while (x>=100000000)
{
if (j>=2)
{
printf("你的错误输入已达3次,你无权再输入!");
return;
}
printf("你输入的金额超出转换范围,请重新输入!");
printf("请输入预转换数额(小于1亿):");
scanf("%lf",&x);
j++;
}
if (x<=0)
{
printf("零元整");
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))
printf("零");
switch (remainder) //输出大写数字
{
case 0:
break;
case 1:
printf("壹");
break;
case 2:
printf("贰");
break;
case 3:
printf("叁");
break;
case 4:
printf("肆");
break;
case 5:
printf("伍");
break;
case 6:
printf("陆");
break;
case 7:
printf("柒");
break;
case 8:
printf("捌");
break;
case 9:
printf("玖");
break;
}
if (remainder>0)
zeroFlag=0;
else if (beginFlag==1)
zeroFlag=1;
if (beginFlag==1) //输出单位
{
if ((i==10000000) && (remainder>0))
printf("仟");
if ((i==1000000) && (remainder>0))
printf("百");
if ((i==100000) && (remainder>0))
printf("十");
if (i==10000)
printf("万");
if ((i==1000) && (remainder>0))
printf("仟");
if ((i==100) && (remainder>0))
printf("百");
if ((i==10) && (remainder>0))
printf("十");
if (i==1)
printf("元");
if ((i>=0.09) && (i<1) && (remainder>0))
printf("角");
if ((i>=0.009) && (i<0.1) && (remainder>0))
printf("分");
}
i=i/10;
}
printf("整\n");
}
这是楼上的朋友的代码,我改成了c语言的,其中有几个需要注意的:
1.c语言中没有bool类型,用其它类型代替就可以了,如:int
2.scanf接收double型数据的时候要加 l 例:scanf(”%lf“,x)
大家一起学习学习:lol:
没人来帮忙解答下吗?:cry #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;
}这个是我复制来的C++ = = 奥特曼先生 发表于 2013-11-29 18:57 static/image/common/back.gif
#include
#include
要c的不过还是谢谢了! maomingkun 发表于 2013-11-29 21:11 static/image/common/back.gif
#include
#include
嗯嗯知道了谢谢了啊!!! 学习无止境 月亮是我瓣弯的 发表于 2013-11-30 09:03 static/image/common/back.gif
学习无止境
可以用单独的一个二维数组来存放那些汉字,然后对每个数字进行处理,查找便可以了。
页:
[1]