将分钟转换为24小时格式

问题描述 投票:0回答:1

当我运行以下功能时,我得到了一些奇怪的结果(为什么不打印出1445,依此类推)。感谢您的帮助。

cout<<"Enter the journey time (minutes) \n"
cin>>journey_time;
cout<<"Enter the first train time \n";
cin>>first_train_time;
cout<<"Enter the last train time \n";
cin>>last_train_time;
cout<<"Enter the frequency time \n";
cin>>frequency_time;
auto get_24hr = [](int minutes){ return (minutes/60)*100 + (minutes%60);};
auto get_minutes = [](int time_24){return (time_24/100)*60+  (time_24 % 100);};

for (int total_min_start= first_train_time; total_min_start <=last_train_time; total_min_start +=frequency_time)
{`
auto x = get_minutes(total_min_start); 
cout<<get_24hr(x)<<" \t "<<get_24hr(x+journey_time+waiting)<<" \t "<<get_24hr(x (2*journey_time+2*waiting)) <<" \t "<<get_24hr(x+(3*journey_time+3*waiting))<<" \t "<<get_24hr(x+(4*journey_time+3*waiting))
}}

输出:

1300 1317 1334 1351 1406

1315 1332 1349 1406 1421

1330 1347 1404 1421 1436

1345 1402 1419 1436 1451

1400 1417 1434 1451 1506

1415 1432 1449 1506 1521

1430 1447 1504 1521 1536

1405 1422 1439 1456 1511 ------->这里的问题:它必须是1445、1504等

1420 1437 1454 1511 1526

1435 1452 1509 1526 1541

1450 1507 1524 1541 1556

1505 1522 1539 1556 1611

1520 1537 1554 1611 1626

1535 1552 1609 1626 1641

c++ c++11 c++14
1个回答
0
投票
Hey @ThomasMatthews/ @Norrius,

If I enter :
journey time : 15 minutes
first_train_time:1300   --->half past nine
last_train_time : 1500  ---> three o clock
frequency_time : 15 minutes

To get the right output, first column starts with specific time 1300 and        increased by (frequency_time) until the specified (last_train_time). 
Second column starts with (first_train_time+frequency_time+2 minutes).
Third column starts with (first_train_time+2*frequency_time+2*2 minutes).
Fourth column starts with (first_train_time+3*frequency_time+3*2 minutes).
Fifth column starts with (first_train_time+4*frequency_time+3*2 minutes).

The output should be: 

col 1     col2    col3   col4    col5
1300      1317    1334   1351    1406
1315      1332    1349   1406    1421
1330      1347    1404   1421    1436
1345      1402    1419   1436    1451
1400      1417    1434   1451    1506
1415      1432    1449   1506    1521
1430      1447    1504   1521    1536
1445      1502    1519   1536    1551 
1500      1517    1534   1551    1606
© www.soinside.com 2019 - 2024. All rights reserved.