【发布时间】:2014-06-25 02:59:39
【问题描述】:
int elapsedtime(int time1, int time2)
{
int minutes1 = ((time1/100*60)+(time1%100);
int minutes2 = ((time2/100*60)+(time2%100);
return(minutes2-minutes1);
}
/************************************************ *******************************************
do
{
cout << "What is your starting time? ";
cin >> time1;
cout << "What is your ending time? ";
cin >> time2;
if (time2>=time1)
{
cout << "Your elapsed time is " << elapsedtime <<endl;
cout << "If you would like to enter other times?(Y/N)" <<endl;
cin >> choice;
}
else
{
cout << "Error: Your starting time must be lower than your ending time."<<endl;
cout << "If you would like to enter other times?(Y/N)" <<endl;
cin >> choice;
}
}
每次经过的时间我都会得到 1 的输出?
【问题讨论】:
-
Integer division 也许??
-
对于一个你正在将所有数学作为丢弃小数部分的整数进行计算,例如
3/2 = 1 -
是的,我需要这样做才能正确转换 24 小时制。