人民币小写转换成大写

#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;
}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值