我是c++的初學者
字串的東西不太清楚
能夠麻煩幫我debug看看嗎?(我不知道問題在哪)
只要輸入就當掉(問題很大)
程式碼滿有點亂請見諒
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
string numturn(int num)
{
switch(num) {
case 1:
return("壹");
case 2:
return("貳");
case 3:
return("參");
case 4:
return("肆");
case 5:
return("伍");
case 6:
return("陸");
case 7:
return("柒");
case 8:
return("捌");
case 9:
return("玖");
case 0:
return("");
}
}//end of numturn()
int main(int argc, char *argv[])
{
char *num[20];int count,i;
string s;
while(cin>>*num) {
s=*num;
count=s.length();
for (i=count;i>=1;i--) {
switch(i) {
case 10:
cout<<numturn(atoi(num[i]))<<"十" ;
break;
case 9:
cout<<numturn(atoi(num[i]))<<"億" ;
break;
case 8:
cout<<numturn(atoi(num[i]))<<"千" ;
break;
case 7:
cout<<numturn(atoi(num[i]))<<"百" ;
break;
case 6:
cout<<numturn(atoi(num[i]))<<"十" ;
break;
case 5:
cout<<numturn(atoi(num[i]))<<"萬" ;
break;
case 4:
cout<<numturn(atoi(num[i]))<<"千" ;
break;
case 3:
cout<<numturn(atoi(num[i]))<<"百" ;
break;
case 2:
cout<<numturn(atoi(num[i]))<<"十" ;
break;
case 1:
cout<<numturn(atoi(num[i]));
break;
}
}
}
return 0;
}
我是c++的初學者
字串的東西不太清楚
能夠麻煩幫我debug看看嗎?(我不知道問題在哪)
只要輸入就當掉(問題很大)
程式碼滿有點亂請見諒
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
string numturn(int num)
{
switch(num) {
case 1:
return("壹");
case 2:
return("貳");
case 3:
return("參");
case 4:
return("肆");
case 5:
return("伍");
case 6:
return("陸");
case 7:
return("柒");
case 8:
return("捌");
case 9:
return("玖");
case 0:
return("");
}
}//end of numturn()
int main(int argc, char *argv[])
{
char *num[20];int count,i;
string s;
while(cin>>*num) {
s=*num;
count=s.length();
for (i=count;i>=1;i--) {
switch(i) {
case 10:
cout<<numturn(atoi(num[i]))<<"十" ;
break;
case 9:
cout<<numturn(atoi(num[i]))<<"億" ;
break;
case 8:
cout<<numturn(atoi(num[i]))<<"千" ;
break;
case 7:
cout<<numturn(atoi(num[i]))<<"百" ;
break;
case 6:
cout<<numturn(atoi(num[i]))<<"十" ;
break;
case 5:
cout<<numturn(atoi(num[i]))<<"萬" ;
break;
case 4:
cout<<numturn(atoi(num[i]))<<"千" ;
break;
case 3:
cout<<numturn(atoi(num[i]))<<"百" ;
break;
case 2:
cout<<numturn(atoi(num[i]))<<"十" ;
break;
case 1:
cout<<numturn(atoi(num[i]));
break;
}
}
}
return 0;
}
指標不是這樣用滴
建議你改用二維陣列試試看吧