| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4137 人关注过本帖
标题:输入两位数,显示该数的英文~ 如何编写(哪里错了)~~
只看楼主 加入收藏
gongyaping
Rank: 4
来 自:广东肇庆怀集
等 级:业余侠客
帖 子:174
专家分:257
注 册:2010-8-1
收藏
得分:0 
学习了。
2010-10-16 17:33
天使的恶魔
Rank: 1
来 自:广东
等 级:新手上路
帖 子:26
专家分:0
注 册:2010-9-14
收藏
得分:0 
回复 10楼 m21wo
然后我这样编了下面:

# include <stdio.h>
# include <stdlib.h>
int main (void)
{
    int x,y,n;
    n=10*x+y;
    printf ("Enter a two-digit number:");
    scanf ("%1d%1d",&x,&y);
    printf("You entered the nember ");
            
  if (n>=20)
   {
    switch (x) {
           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;     
           }
    switch (y) {
           case 0:  printf("");           break;      
           case 1:  printf("one");        break;   
           case 2:  printf("two");        break;   
           case 3:  printf("three");      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;
           }  
    }
  else
    {
    switch (n) {
           case 10: printf("ten");        break;     
           case 11: printf("eleven");     break;
           case 12: printf("twelve");     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;
           }
    }                        
    system ("pause");
    return 0;
}

可是红色部分好像没有作用,我输入 10 的时候,显示的是“”(也就是空格)


又是哪里错了呢?









记住我最好的方式就是忘了我
2010-10-16 19:08
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
程序代码:
# include <stdio.h>
# include <stdlib.h>
int main (void)
{
    int x,y,n;
   
    printf ("Enter a two-digit number:");
    scanf ("%1d%1d",&x,&y);
    printf("You entered the nember ");
    n=10*x+y;                                       // 要放在输入x,y 之后!放在之前系统不知道x,y多少,就会出错!
            
  if (n>=20)
   {
    switch (x) {
           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;    
           }
    switch (y) {
           case 0:  printf("");           break;      
           case 1:  printf("one");        break;   
           case 2:  printf("two");        break;   
           case 3:  printf("three");      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;
           } 
    }
  else
    {
    switch (n) {
           case 10: printf("ten");        break;    
           case 11: printf("eleven");     break;
           case 12: printf("twelve");     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;
           }
    }                       
    system ("pause");
    return 0;
}

If You Want Something, Go Get It, Period.
2010-10-16 20:45
天使的恶魔
Rank: 1
来 自:广东
等 级:新手上路
帖 子:26
专家分:0
注 册:2010-9-14
收藏
得分:0 
回复 13楼 m21wo
嗯嗯,明白
请你看一下如果 要输出 00到 09 就又不对了
# include <stdio.h>
# include <stdlib.h>
int main (void)
{
    int x,y,n;
   
    printf ("Enter a two-digit number:");
    scanf ("%1d%1d",&x,&y);
    printf("You entered the nember ");
    n=10*x+y;
     
     
  if (n>=20)
   {
    switch (x) {
           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;     
           }
    switch (y) {
           case 0:  printf("");           break;      
           case 1:  printf("one");        break;   
           case 2:  printf("two");        break;   
           case 3:  printf("three");      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;
           }  
    }
  else
    {
    switch (n) {
           case 00: printf("zero");       break;
           case 01: printf("one");        break;
           case 02: printf("two");        break;
           case 03: printf("three");      break;
           case 04: printf("four");       break;
           case 05: printf("five");       break;
           case 06: printf("six");        break;
           case 07: printf("seven");      break;
           case 08: printf("eight");      break;      //这行调试时出错
           case 09: printf("nine");       break;      //这行调试时出错   
           case 10: printf("ten");        break;     
           case 11: printf("eleven");     break;
           case 12: printf("twelve");     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;
           }
    }
           
           
  
    system ("pause");
    return 0;
}


红色是我增加的部分,可是最后两行,08,09 有错
可是前面几行都没错,我就不明白了~~请教一下~
真的不好意思麻烦你,谢谢啦~


记住我最好的方式就是忘了我
2010-10-16 21:53
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
程序代码:
# include <stdio.h>
# include <stdlib.h>
int main (void)
{
    int x,y,n;
   
    printf ("Enter a two-digit number:");
    scanf ("%1d%1d",&x,&y);
    printf("You entered the nember ");
    n=10*x+y;
    
    
  if (n>=20)
   {
    switch (x) {
           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;    
           }
    switch (y) {
           case 0:  printf("");           break;      
           case 1:  printf("one");        break;   
           case 2:  printf("two");        break;   
           case 3:  printf("three");      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;
           } 
    }
  else
    {
    switch (n) {
           case 0: printf("zero");       break;
           case 1: printf("one");        break;
           case 2: printf("two");        break;
           case 3: printf("three");      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;      //这行调试时出错   
           case 10: printf("ten");        break;    
           case 11: printf("eleven");     break;
           case 12: printf("twelve");     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;
           }
    }
          
          

 
    system ("pause");
    return 0;
}


n已经算出来了,是整数,8就是8,不会是08

If You Want Something, Go Get It, Period.
2010-10-16 22:00
天使的恶魔
Rank: 1
来 自:广东
等 级:新手上路
帖 子:26
专家分:0
注 册:2010-9-14
收藏
得分:0 
回复 15楼 m21wo
噢噢。我终于明白了,应该没有问题了
非常感谢!~

记住我最好的方式就是忘了我
2010-10-16 22:08
初学者还重名
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-9-14
收藏
得分:0 
请问上面的int m=x-'0';
    int n=y-'0';
    int s=10*m+n;
是什么意思啊?
2011-09-14 22:09
快速回复:输入两位数,显示该数的英文~ 如何编写(哪里错了)~~
数据加载中...
 
   



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

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