大神,求解。。。。。
程序:就是输入一个小于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 编辑 ]