for(;val!=0;val/=10)
{
//用val%10依次取出各个值
//用switch转换成大写
}
但是依次取出来的数是重个位开始的.................
如果是整百之类的应该输出"壹百元整"而不是"壹百零十零元整".........
请高手指点一下
谢过了
哎~没人帮我~自食其力! #include<iostream> #include<vector>
using namespace std;
void main() { void change(int n); void unit(int n); int i(0); int val; cout<<"enter val:";//val是前面传下来的值 cin>>val; //输入为了调程序 vector<int>num(i); while(val) { num[i]=val%10; i++; val/=10; } for(;i>=1;i--) { change(num[i-1]); unit(i); } cout<<"整"<<endl; }
void change(int n) { switch(n) { case 0: cout<<"零"; break; case 1: cout<<"壹"; break; case 2: cout<<"贰"; break; case 3: cout<<"叁"; break; case 4: cout<<"肆"; break; case 5: cout<<"伍"; break; case 6: cout<<"陆"; break; case 7: cout<<"柒"; break; case 8: cout<<"捌"; break; case 9: cout<<"玖"; break; } }
void unit(int n) { switch(n) { case 1: cout<<"元"; break; case 2:case 6:case 10: cout<<"拾"; break; case 3:case 7: cout<<"佰"; break; case 4:case 8: cout<<"千"; break; case 5: cout<<"万"; break; case 9: cout<<"亿"; break; } } 比较复杂 而且第二个问题没有解决 哪位高手帮忙改一下 还有 每次都出现下面这个
我帮你改了下, 现在可以运行了.. #include<iostream>
using namespace std;
void main() { void change(int n); void unit(int n); int i=0; int val; int num[100]; cout<<"enter val:";//val是前面传下来的值 cin>>val; //输入为了调程序
while(val) { ++i; num[i]=val%10; val/=10; if(val==0) break; }
for(;i>=1;i--) { change(num[i]); unit(i); } cout<<"整"<<endl; }
void change(int n) { switch(n) { case 0: cout<<"零"; break; case 1: cout<<"壹"; break; case 2: cout<<"贰"; break; case 3: cout<<"叁"; break; case 4: cout<<"肆"; break; case 5: cout<<"伍"; break; case 6: cout<<"陆"; break; case 7: cout<<"柒"; break; case 8: cout<<"捌"; break; case 9: cout<<"玖"; break; default: cout<<"error"<<endl; } }
void unit(int n) { switch(n) { case 1: cout<<"元"; break; case 2:case 6:case 10: cout<<"拾"; break; case 3:case 7: cout<<"佰"; break; case 4:case 8: cout<<"千"; break; case 5: cout<<"万"; break; case 9: cout<<"亿"; break; default: cout<<"error"<<endl; } }