| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 307 人关注过本帖
标题:大神,求解。。。。。
只看楼主 加入收藏
zsk423
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-9-29
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
大神,求解。。。。。
程序:就是输入一个小于1000的整数,输出整数的英文,比如输入234,输出two hundred and thirty four。我用的方法比较笨,但还是错了,请教各位错在哪里?
程序代码:
#include <stdbool.h>
#include <stdlib.h>
int main()
{
  
    char number[8];
    bool input=true;
    char e_gewei[]="";
    char e_shiwei[]="";
    char e_baiwei[]="";
    while(input)
    {
        printf("enter the integer(1-1000):\n");
        fgets(number,8,stdin);
        int j=0;
        for(j=0;j<=strlen(number)-2;++j)
        {
            if(strlen(number)<=4&&isdigit(number[j])&&atoi(number)!=0)
            {
                input=false;
               
            }
            else
            {
                printf("you enter wrong,please enter again.");
                input=true;
                break;
            }
        }
    }    
    int gewei,shiwei,baiwei;
    gewei=atoi(number)/100;
    if(gewei!=0)
    {
       
        switch(gewei)
        {
               case 1:
                    strcat(e_gewei,"one");
                    break;
               case 2:
                    strcat(e_gewei,"two");
                    break;
               case 3:
                    strcat(e_gewei,"three");
                    break;
               case 4:
                    strcat(e_gewei,"four");
                    break;
               case 5:
                    strcat(e_gewei,"five");
                    break;
               case 6:
                    strcat(e_gewei,"six");
                    break;
               case 7:
                    strcat(e_gewei,"seven");
                    break;
               case 8:
                    strcat(e_gewei,"eight");
                    break;
               case 9:
                    strcat(e_gewei,"nine");
                    break;
        }
    }
    shiwei=(atoi(number)%100)/10;
    baiwei=atoi(number)%10;
    switch(shiwei)
    {
                  case 1:
                  {
                       switch(baiwei)
                       {
                                case 1:
                                     strcat(e_shiwei,"eleven");
                                     break;
                                case 2:
                                     strcat(e_shiwei,"twelve");
                                     break;
                                case 3:
                                     strcat(e_shiwei,"twelve");
                                     break;
                                case 4:
                                     strcat(e_shiwei,"fourteen");
                                     break;
                                case 5:
                                     strcat(e_shiwei,"fifteen");
                                     break;
                                case 6:
                                     strcat(e_shiwei,"sixteen");
                                     break;
                                case 7:
                                     strcat(e_shiwei,"seventeen");
                                     break;
                                case 8:
                                     strcat(e_shiwei,"eighteen");
                                     break;
                                case 9:
                                     strcat(e_shiwei,"nineteen");
                                     break;
                                default:
                                        strcat(e_shiwei,"ten");
                       }
                        break;
                  }
                  case 2:
                       strcat(e_shiwei,"twenty");
                       break;
                  case 3:
                       strcat(e_shiwei,"thirty");
                       break;
                  case 4:
                       strcat(e_shiwei,"forty");
                       break;
                  case 5:
                       strcat(e_shiwei,"fifty");
                       break;
                  case 6:
                       strcat(e_shiwei,"sixty");
                       break;
                  case 7:
                       strcat(e_shiwei,"seventy");
                       break;
                  case 8:
                       strcat(e_shiwei,"eighty");
                       break;
                  case 9:
                       strcat(e_shiwei,"ninty");
                       break;
    }
    if(shiwei!=1)
    {
        switch(baiwei)
        {
      
                  case 1:
                       strcat(e_baiwei," one");
                  case 2:
                       strcat(e_baiwei," two");
                  case 3:
                       strcat(e_baiwei," three");
                  case 4:
                       strcat(e_baiwei," four");
                  case 5:
                       strcat(e_baiwei," five");
                  case 6:
                       strcat(e_baiwei," six");
                  case 7:
                       strcat(e_baiwei," seven");
                  case 8:
                       strcat(e_baiwei," eigth");
                  case 9:
                       strcat(e_baiwei," nine");
       }
    }
    strcat(e_shiwei,e_baiwei);
    printf("\n%s %s %s",e_gewei,(gewei==0?"":"hundred and"),e_shiwei);
    system("pause");
    return 0;
}


[ 本帖最后由 zsk423 于 2012-9-29 21:48 编辑 ]
搜索更多相关主题的帖子: 英文 
2012-09-29 21:21
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:7 
char e_gewei[]="";
    char e_shiwei[]="";
    char e_baiwei[]="";

这是个啥。。。
2012-09-29 21:23
zsk423
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-9-29
收藏
得分:0 
回复 2楼 zklhp
e_gewei[]是第一个数字的英文
e_shiwei[]是第二个数字的英文
e_baiwei[]是第三个数字的英文

一开始初始化为空
2012-09-29 21:50
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:7 
回复 3楼 zsk423
这么初始化,数组大小是多少?

总有那身价贱的人给作业贴回复完整的代码
2012-09-29 23:01
q13678986740
Rank: 4
等 级:业余侠客
帖 子:114
专家分:245
注 册:2012-7-7
收藏
得分:7 
我也用这么笨的方法做过。
main()
{   int a,b,c,d,e,f,g;
    printf("请输入一个四位数");
    scanf("%d",&a);
    if(a<1000||a>9999)
        printf("输入错误");
    else
    {
        b=a%1000;
        c=(a-b)/1000;/*qianwei*/
        d=b%100;
        e=(b-d)/100;/*baiwei*/
        f=d%10;/*gewei*/
        g=(d-f)/10;/*shiwei*/
        switch(c)
        {case 1:printf("one");break;
        case 2:printf("two");break;
        case 3:printf("tree");break;
        case 4:printf("four");break;
        case 5:printf("five");break;
        case 6:printf("six");break;
        case 7:printf("seven");break;
        case 8:printf("eight");break;
        case 9:printf("nine");break;

        }
        printf(" thousand ");
        switch(e)
        {
        case 1:printf("one");break;
        case 2:printf("two");break;
        case 3:printf("tree");break;
        case 4:printf("four");break;
        case 5:printf("five");break;
        case 6:printf("six");break;
        case 7:printf("seven");break;
        case 8:printf("eight");break;
        case 9:printf("nine");break;

        }
        if(e!=0)
            printf(" hundard ");
        if(d!=0)
        printf(" and ");

        if(g==0&&(f!=0))

                 switch(f)
                   {case 1:printf("one");break;
                    case 2:printf("two");break;
                    case 3:printf("tree");break;
                    case 4:printf("four");break;
                    case 5:printf("five");break;
                    case 6:printf("six");break;
                    case 7:printf("seven");break;
                    case 8:printf("eight");break;
                    case 9:printf("nine");break;
                    }

        if(g!=0&&d>9&&d<20)
                 switch(d)
                        {case 10:printf("ten");break;
                         case 11:printf("eleven");break;
                         case 12:printf("twele");break;
                         case 13:printf("thirteen");break;
                         case 14:printf("fourteen");break;
                         case 15:printf("fifteen");break;
                         case 16:printf("sixteen");break;
                         case 17:printf("seventeen");break;
                         case 18:printf("eighteen");break;
                         case 19:printf("nineteen");break;
                        }
               else if(d>=20)
                    {  switch(g)
                        {case 1:printf("ten");break;
                         case 2:printf("twenty");break;
                         case 3:printf("thirty");break;
                         case 4:printf("forty");break;
                         case 5:printf("fifty");break;
                         case 6:printf("sixty");break;
                         case 7:printf("seventy");break;
                         case 8:printf("eighty");break;
                         case 9:printf("ninety");break;
                        }
                         printf(" ");
                       switch(f)
                        {case 1:printf("one");break;
                         case 2:printf("two");break;
                         case 3:printf("tree");break;
                         case 4:printf("four");break;
                         case 5:printf("five");break;
                         case 6:printf("six");break;
                         case 7:printf("seven");break;
                         case 8:printf("eight");break;
                         case 9:printf("nine");break;
                         }
               
                      }





    }
    getch();
}
2012-09-30 12:45
快速回复:大神,求解。。。。。
数据加载中...
 
   



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

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