本文介绍了我需要帮助,在此程序中,我想将数字转换为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// help num2word.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
char one[10][10] = {"One", "Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char ten[15][15] = {"Ten","Eleven","Tweleve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
char tens[15][15] = {"Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
int main()
{
int num , n , r , c = 0 ;
cout << "please enter the number :" << endl ;
cin >> num ;
n = num ;
while( n )
{
r = n % 10 ;
n = n / 10 ;
c++ ;
}
switch(c)
{
case 1:
if( num >0 && num < 10 )
{
cout << one[num-1];
}else{
cout<< "ZERO ";
}
break;
case 2:
/*if( num > 10 && num < 20 )
cout<<"yay"<<ten[num-10];
if( num > 20 && num < 100 )
cout << tens[num/10-2] ;
*/
( num > 10 && num < 20 ) ? (cout << ten[num-10]) :( cout << tens[num/10-1] && ((num%10)?one(num%10):1));
break;
}
return 0;
}
</iostream>
我的程序从0到19的数字是正确的,但是它不能写55-> 55.
只写五十,我不知道该怎么办?
和ia在((cout< 但我不知道为什么?
my program for numbers from 0 till 19 is true but it cant write 55 ->fifty five
and just write fifty , i dont know what should i do ?
and ia have an error in ((cout << ten[num-10]) :( cout << tens[num/10-1] && ((num%10)?one(num%10):1));)
but i dont know why ?
推荐答案
这篇关于我需要帮助,在此程序中,我想将数字转换为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!