我想实现一个支票的 打印就是把数字变成英文额
代码如下:
#include <iostream.h>
#include <string>
//用于返回小于10的函数
string digit_name(int n)
{
if (1==n) return "one";
if (2==n) return "two";
if (3==n) return "three";
if (4==n) return "four";
if (5==n) return "five";
if (6==n) return "six";
if (7==n) return "seven";
if (8==n) return "eight";
if (9==n) return "nine";
return " ";
}
//用于返回小于20的函数
string teen_name(int n)
{
if (10==n) return "ten";
if (11==n) return "eleven";
if (12==n) return "twelve";
if (13==n) return "thirteen";
if (14==n)return "fourteen";
if (15==n) return "fifteen";
if (16==n) return "sixteen";
if (17==n) return "seventeen";
if (18==n) return "eighteen";
if (19==n) return "ninteen";
return " ";
}
//用于返回小于100的函数
string teens_name(int n)
{
if (2==n) return "twenty";
if (3==n) return "thirty";
if (4==n) return "forty";
if (5==n) return "fifty";
if (6==n) return "sixty";
if (7==n) return "seventy";
if (8==n) return "eighty";
if (9==n) return "ninty";
return "";
}
//用于返回大于1000的函数
string int_name(int n)
{
int c=n;
string r;
if (c>=1000)
{
r=int_name(c/1000) + "thousand";
c=c%1000;
}
if (c>=100)
{
r=r+digit_name(c/100) + "handred";
c=c%100;
}
if (c>=20)
{
r=r + teens_name(c/10);
c=c%10;
}
if(c>=10)
{
r= r + teen_name(c);
c=0
}
if (c>0)
{
r=r+digit_name(c);
return r;
}
}
//main函数
int main()
{
int n;
cout<<"请输入你要转化的金额:"<<endl;
cin>>n;
cout<<int_name(n);
return 0;
}
错误提示如下:
--------------------Configuration: intname - Win32 Debug--------------------
Compiling...
intname.cpp
E:\vc++\add\intname\intname.cpp(7) : error C2146: syntax error : missing ';' before identifier 'digit_name'
E:\vc++\add\intname\intname.cpp(7) : error C2501: 'string' : missing storage-class or type specifiers
E:\vc++\add\intname\intname.cpp(7) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
intname.exe - 1 error(s), 0 warning(s)