| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:vc模拟银行常用打印程序,哪错了?
只看楼主 加入收藏
初学者请指教
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-5-10
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
vc模拟银行常用打印程序,哪错了?
#include<stdio.h>
int main()
{
    char Number[128];
    char Interger[64],Decimal[64];
    int lenI,lenD;
    int i,j;
    void PrintInterger(char a[],int len);
    void PrintDecimal(char a[],int len);
    puts("********************************\n");
    puts("*  this is a print program   *\n");
    puts("*     used in a bank         *\n");
    puts("********************************\n");
    puts("please input the money:");
    gets(Number);
    i=0;j=0;
    while((Number[i]!='\0')&&(Number[i]!='.'))
    {
        Interger[i]=Number[i];
        i++;
    }
    lenI=i;
    PrintInterger(Interger,lenI);
    if(Number[i]=='.')
    {
        i++;
        while(Number[i]!='\0')
            Decimal[j++]=Number[i++];
        if((j>=4)&&(Decimal[4]>='5'))
        {   
            Decimal[3]+=1;
            Decimal[4]='\0';
        }
    if(j>=4)
        lenD=4;
    else
        lenD=j;
    PrintDecimal(Decimal,lenD);
    }
    getchar();
    return 0;
}
void PrintInterger(char a[],int len)
{
    int i,j;
    printf("你的钱数是: \n");
    for(i=0,j=len-1;(a[i]!='.')&&(a[i]!='\0');i++,j--)
    {
        switch(a[i])
        {
        case'0':
            {
                do
                {
                    i++;
                    j--;
                }while(a[i]!=0);
                printf("%s","零");
                break;
            }
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        case'5':
            printf("%s","伍");break;
        case'6':
            printf("%s","陆");break;
        case'7':
            printf("%s","柒");break;
        case'8':
            printf("%s","捌");break;
        case'9':
            printf("%s","玖");break;
        default:
            printf("error");break;
        }
        switch(j)
        {
        case'1':
            printf("%s","个");break;
        case'2':
            printf("%s","十");break;
        case'3':
            printf("%s","百");break;
        case'4':
            printf("%s","千");break;
        case'5':
            printf("%s","万");break;
        case'6':
            printf("%s","十万");break;
        case'7':
            printf("%s","百万");break;
        case'8':
            printf("%s","千万");break;
        case'9':
            printf("%s","忆");break;
        default:
            printf("%s",' ');break;
        }
    }
}
void PrintDecimal(char a[],int len)
{
    int i;
    for(i=0;i<=len;i++)
    {
        switch(a[i])
        {
        case'0':
            printf("%s","零");break;
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        case'5':
            printf("%s","伍");break;
        case'6':
            printf("%s","陆");break;
        case'7':
            printf("%s","柒");break;
        case'8':
            printf("%s","捌");break;
        case'9':
            printf("%s","玖");break;
        default:
            printf("error");break;
        }
        switch(a[i])
        {
        case'0':
            printf("%s","零");break;
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        }
    }
}
哪错了,求大神指教
搜索更多相关主题的帖子: include please money 
2013-05-14 12:50
Explorerlxz
Rank: 9Rank: 9Rank: 9
来 自:zzu
等 级:蜘蛛侠
威 望:4
帖 子:302
专家分:1032
注 册:2013-4-24
收藏
得分:20 
#include<stdio.h>
int main()
{
    char Number[128];
    char Interger[64],Decimal[64];
    int lenI,lenD;
    int i,j;
    void PrintInterger(char a[],int len);
    void PrintDecimal(char a[],int len);
    puts("********************************\n");
    puts("*  this is a print program   *\n");
    puts("*     used in a bank         *\n");
    puts("********************************\n");
    puts("please input the money:");
    gets(Number);
    i=0;j=0;
    while((Number[i]!='\0')&&(Number[i]!='.'))
    {
        Interger[i]=Number[i];
        i++;
    }
    lenI=i;
    PrintInterger(Interger,lenI);
    if(Number[i]=='.')
    {
        i++;
        while(Number[i]!='\0')
            Decimal[j++]=Number[i++];
        if((j>=4)&&(Decimal[4]>='5'))
        {   
            Decimal[3]+=1;
            Decimal[4]='\0';
        }
    if(j>=4)
        lenD=4;
    else
        lenD=j;
    PrintDecimal(Decimal,lenD);
    }
    getchar();
    return 0;
}
void PrintInterger(char a[],int len)
{
    int i,j;
    printf("你的钱数是: \n");
    for(i=0,j=len-1;(a[i]!='.')&&(a[i]!='\0');i++,j--)
    {
        switch(a[i])
        {
        case'0':
            {
                do
                {
                    i++;
                    j--;
                }while(a[i]!=0);
                printf("%s","零");
                break;
            }
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        case'5':
            printf("%s","伍");break;
        case'6':
            printf("%s","陆");break;
        case'7':
            printf("%s","柒");break;
        case'8':
            printf("%s","捌");break;
        case'9':
            printf("%s","玖");break;
        default:
            printf("error");break;
        }
        switch(j)//这里最大的错误是没认识到j是整型,不是字符型
        {
        case'1':
            printf("%s","个");break;
        case'2':
            printf("%s","十");break;
        case'3':
            printf("%s","百");break;
        case'4':
            printf("%s","千");break;
        case'5':
            printf("%s","万");break;
        case'6':
            printf("%s","十万");break;
        case'7':
            printf("%s","百万");break;
        case'8':
            printf("%s","千万");break;
        case'9':
            printf("%s","忆");break;
        default:
            printf("%s",' ');break;//这里为何前面用双引号,后面用单引号
        }
    }
}
void PrintDecimal(char a[],int len)
{
    int i;
    for(i=0;i<=len;i++)
    {
        switch(a[i])
        {
        case'0':
            printf("%s","零");break;
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        case'5':
            printf("%s","伍");break;
        case'6':
            printf("%s","陆");break;
        case'7':
            printf("%s","柒");break;
        case'8':
            printf("%s","捌");break;
        case'9':
            printf("%s","玖");break;
        default:
            printf("error");break;
        }
        switch(a[i])//这个switch有什么用?
        {
        case'0':
            printf("%s","零");break;
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        }
    }
}
我大致改了一下,也许还有漏洞,这就要楼主自己去发现了。
#include<stdio.h>
int main()
{
    char Number[128]={'\0'};
    char Interger[64]={'\0'},Decimal[64]={'\0'};
    int lenI,lenD;
    int i,j;
    void PrintInterger(char a[],int len);
    void PrintDecimal(char a[],int len);
    puts("********************************\n");
    puts("*  this is a print program   *\n");
    puts("*     used in a bank         *\n");
    puts("********************************\n");
    puts("please input the money:");
    gets(Number);
    i=0;j=0;
    while((Number[i]!='\0')&&(Number[i]!='.'))
    {
        Interger[i]=Number[i];
        i++;
    }
    lenI=i;
    PrintInterger(Interger,lenI);
    if(Number[i]=='.')
    {
        i++;
        while(Number[i]!='\0')
            Decimal[j++]=Number[i++];
        if((j>=4)&&(Decimal[4]>='5'))
        {   
            Decimal[3]+=1;
            Decimal[4]='\0';
        }
    if(j>=4)
        lenD=4;
    else
        lenD=j;
    printf("点");
    PrintDecimal(Decimal,lenD);
    }
    getchar();
    return 0;
}
void PrintInterger(char a[],int len)
{
    int i,j;
    printf("你的钱数是: \n");
    for(i=0,j=len;(a[i]>='0')&&(a[i]<='9')&&j>0;i++,j--)
    {   
       switch(a[i])
        {
        case'0':
            {
                do
                {
                    i++;
                    j--;
                }while(a[i]==0);//
                printf("%s","零");
                i--,j++;
                break;
            }
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        case'5':
            printf("%s","伍");break;
        case'6':
            printf("%s","陆");break;
        case'7':
            printf("%s","柒");break;
        case'8':
            printf("%s","捌");break;
        case'9':
            printf("%s","玖");break;
        default:
            printf("error");break;
        }
        switch(j)
        {
        case 1:
            printf("%s","元");break;
        case 2:
            printf("%s","十");break;
        case 3:
            printf("%s","百");break;
        case 4:
            printf("%s","千");break;
        case 5:
            printf("%s","万");break;
        case 6:
            printf("%s","十万");break;
        case 7:
            printf("%s","百万");break;
        case 8:
            printf("%s","千万");break;
        case 9:
            printf("%s","亿");break;
        default:
            printf("%s"," ");break;
        }
    }
}
void PrintDecimal(char a[],int len)
{
    int i;
    for(i=0;i<=len;i++)
    {
        switch(a[i])
        {
        case'0':
            printf("%s","零");break;
        case'1':
            printf("%s","壹");break;
        case'2':
            printf("%s","贰");break;
        case'3':
            printf("%s","叁");break;
        case'4':
            printf("%s","肆");break;
        case'5':
            printf("%s","伍");break;
        case'6':
            printf("%s","陆");break;
        case'7':
            printf("%s","柒");break;
        case'8':
            printf("%s","捌");break;
        case'9':
            printf("%s","玖");break;
        default:
           break;
        }
      }
}
2013-05-16 19:58
快速回复:vc模拟银行常用打印程序,哪错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.072437 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved