C++编程 输入数字转换成对应的时间

我的代码其中分钟十位输不出来求大神看看哪里错了#include<iostream>#include<string>usingnamespacestd;inttrans(i... 我的代码其中分钟十位输不出来 求大神看看哪里错了

#include<iostream>
#include<string>
using namespace std;
int trans(int hours, int min, string &day, string &ho, string &minu1, string&minu2)
{
int a;
a = hours % 12;
switch (a)
{
case 0: if (hours == 0) day = "Midnight";
else day = "Noon";
ho = "";
break;
case 1: if (hours == 1) day = " AM";
else day = " PM";
ho = "One";
break;
case 2: if (hours == 2) day = " AM";
else day = " PM";
ho = "Two";
break;
case 3: if (hours == 3) day = " AM";
else day = " PM";
ho = "Three";
break;
case 4: if (hours == 4) day = " AM";
else day = " PM";
ho = "Four";
break;
case 5: if (hours == 5) day = " AM";
else day = " PM";
ho = "Five";
break;
case 6: if (hours == 6) day = " AM";
else day = " PM";
ho = "Six";
break;
case 7: if (hours == 7) day = " AM";
else day = " PM";
ho = "Seven";
break;
case 8: if (hours == 8) day = " AM";
else day = " PM";
ho = "Eight";
break;
case 9: if (hours == 9) day = " AM";
else day = " PM";
ho = "Nine";
break;
case 10: if (hours == 10) day = " AM";
else day = " PM";
ho = "Ten";
break;
case 11: if (hours == 11) day = " AM";
else day = " PM";
ho = "Eleven";
break;

}
int b;
b = min % 10;
switch (b)
{
case 1:if (min != 11) minu2 = " one";
else minu2 = " eleven";
break;
case 2:if (min != 12) minu2 = " two";
else minu2 = " twelve";
break;
case 3:if (min != 13) minu2 = " three";
else minu2 = " thirteen";
break;
case 4:if (min != 14) minu2 = " four";
else minu2 = " fourteen";
break;
case 5:if (min != 15) minu2 = " five";
else minu2 = " fifteen";
break;
case 6:if (min != 16) minu2 = " six";
else minu2 = " sixteen";
break;
case 7:if (min != 17) minu2 = " seven";
else minu2 = " seventeen";
break;
case 8:if (min != 18) minu2 = " eight";
else minu2 = " eighteen";
break;
case 9:if (min != 19) minu2 = " nine";
else minu2 = " nineteen";
break;
case 0: minu2 = "";
break;

}
int c;
c = min /10;
switch (c)
{
case 0:minu1 = "";
break;
case 1:minu1 = "";
break;
case 2:minu1 == " twenty";
break;
case 3:minu1 == " thirty";
break;
case 4:minu1 == " forty";

break;
case 5:minu1 == " fifty";
break;
case 6:minu1 == " sixty";
break;
default:cout << "error time";
}
return 0;
}
void main()
{
int a, b,c;
c = 1;
cout << "Please input the time" << endl;
cin >> a >> b;
while (c)
{
string day, ho, minu1, minu2;
trans(a, b, day, ho, minu1, minu2);
cout << ho << minu1 << minu2 << day<<endl;
cin >> a >> b;
}
system("pause");
}
展开
 我来答
唔知吴魏
2014-12-01 · TA获得超过107个赞
知道答主
回答量:124
采纳率:0%
帮助的人:96.6万
展开全部
首先说,这代码写的太冗余了,最重要的是,你这代码里两个表示分钟的是什么意思啊

#include<iostream>
#include<string>
using namespace std;
void trans(int hours, int min, string &day, string &ho, string &minu1, string &minu2)
{
if(hours == 0) day = "Midnight";
else if(hours>12 ) day = " PM";
else day = " AM";
string num[]={"" ,"One", "Two" ,"Three", "Four", "Five","Six"," Seven","Eight" ,"Nine" , "Ten",
"Eleven", "Twelve", " Thirteen"," Fourteen"," Fifteen"," Sixteen"," Seventeen","Eighteen"," Nineteen",
"Twenty", " Thirty"," Forty"," Fifty"," Sixty"};
ho=num[hours];
if(min<20)
{
minu1="";
minu2=num[min];
}
else
{
minu1=num[min/10+18];
minu2=num[min%10];
}
}
void main()
{
int a, b,c; c = 1;
cout << "Please input the time" << endl;
cin >> a >> b;
while (c)
{
string day, ho, minu1, minu2;
trans(a, b, day, ho, minu1, minu2);
cout << ho << minu1 << minu2 << day<<endl;
cin >> a >> b;
}
system("pause");
}
追问
第一个是分钟的十位 第二个是分钟的个位啊~~~                呵呵你有冗长的吗!?
追答
知道了 等下 马上好
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
geniepengsz
2014-12-01 · TA获得超过2万个赞
知道大有可为答主
回答量:1.2万
采纳率:97%
帮助的人:2355万
展开全部
调试了一下代码,这一段代码有问题:把赋值"="用成“==”了,赋值变成了比较导致分钟的十位没有值,把“==”改成“=“可解决这一问题。如下注释。
switch (c)
{
case 0:minu1 = "";
break;
case 1:minu1 = "";
break;
//case 2:minu1 == " twenty";
case 2:minu1 = " twenty";
break;
//case 3:minu1 == " thirty";
case 3:minu1 = " thirty";
break;
//case 4:minu1 == " forty";
case 4:minu1 = " forty";
break;
//case 5:minu1 == " fifty";
case 5:minu1 = " fifty";
break;
//case 6:minu1 == " sixty";
case 6:minu1 = " sixty";
break;
default:cout << "error time";
}
供参考。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
洒水车生产厂家01
2015-09-28 · TA获得超过6784个赞
知道小有建树答主
回答量:1136
采纳率:20%
帮助的人:228万
展开全部
调试了一下代码,这一段代码有问题:把赋值"="用成“==”了,赋值变成了比较导致分钟的十位没有值,把“==”改成“=“可解决这一问题。如下注释。
switch (c)
{
case 0:minu1 = "";
break;
case 1:minu1 = "";
break;
//case 2:minu1 == " twenty";
case 2:minu1 = " twenty";
break;
//case 3:minu1 == " thirty";
case 3:minu1 = " thirty";
break;
//case 4:minu1 == " forty";
case 4:minu1 = " forty";
break;
//case 5:minu1 == " fifty";
case 5:minu1 = " fifty";
break;
//case 6:minu1 == " sixty";
case 6:minu1 = " sixty";
break;
default:cout << "error time";
}
供参考。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式