I have a homework - I must to create script with time of broadcasting. Broadcasting is when time is for example 12:21 or 02:20 - just the same from behind and from the begin too. I want that time writes in HH:MM format. All works good but up to one thing.. When time < 10 it not was in HH:MM format but is in H:MM format example - 04:40 outputs as 4:40 - It's a problem.
#include <iostream>
#include <string>
#include <queue>
#include <tuple>
#include <limits>
int main() {
std::cout << "Give me a number: " << std::endl;
int c;
std::cin >> c;
if (c < 1) {
std::cout << "Incorrect!." << std::endl;
main();
}
else if (c > 2000) {
std::cout << "Incorrect!" << std::endl;
main();
}
else {
std::cout << "Correct value." << std::endl;
std::queue<std::tuple<int, int>> casy;
for (int i = 0; i < c; i++) {
std::cout << "Give me a time number. " << i << " (HH:MM): ";
int hour, minute;
char c;
std::cin >> hour >> c >> minute;
std::cin.clear();
std::cin.ignore(10000, '\n');
/* Uložení času do fronty [std::queue] */
casy.push(std::make_tuple(hour, minute));
}
for (int u = 0; u = times.size(); u++) {
int broadcastingTimes[15][2] = { { 01, 10 },{ 02, 20 },{ 03, 30 },{ 04, 40 },{ 05, 50 },{ 10, 01 },{ 11, 11 },{ 12, 21 },{ 13, 31 },{ 14, 41 },{ 15, 51 },{ 20, 02 },{ 21, 12 },{ 22, 22 },{ 23, 32 } };
int actuallyBroadcastingIndex = 0;
for (int o = 0; o < 15; o++) {
if (std::get<0>(times.front()) == broadcastingTimes[o][0]) {
if (std::get<1>(times.front()) <= broadcastingTimes[o][1]) {
/*if(o != 0) {
if(std::get<0>(times.front()) > broadcastingTimes[o-1][0]) {
if(std::get<0>(times.front()) > broadcastingTimes[o-1][1]) {
actuallyBroadcastingIndex = o;
} else {
actuallyBroadcastingIndex = o-1;
}
} else {
actuallyBroadcastingIndex = o;
}
} else {
actuallyBroadcastingIndex = o;
}*/
actuallyBroadcastingIndex = o;
}
else {
actuallyBroadcastingIndex = o + 1;
}
if (std::get<0>(times.front()) == 23) {
if (std::get<1>(times.front()) > 32) {
actuallyBroadcastingIndex = 0;
}
}
}
else if (std::get<0>(times.front()) > broadcastingTimes[o][0] & std::get<0>(times.front()) < broadcastingTimes[o + 1][0]) {
//std::cout << std::get<0>(casy.front()) << "/" << broadcastingTimes[o][0] << "\n";
actuallyBroadcastingIndex = o + 1;
}
}
int hourInput = std::get<0>(times.front());
std::string timeInputedByUser = std::to_string(hourInput) + ":" + std::to_string(std::get<1>(times.front()));
std::string broadcastingTimeActually = std::to_string(broadcastingTimes[actuallyBroadcastingIndex][0]) + ":" + std::to_string(broadcastingTimes[actuallyBroadcastingIndex][1]);
//std::cout << "sss" << broadcastingTimes[actuallyBroadcastingIndex][0] << "\n";
std::cout << "Nearest broadcasting from " << timeInputedByUser << " will be at " << broadcastingTimeActually << std::endl;
casy.pop();
std::cin.get();
}
}
return 0;
}
Expected results are: if nearest broadcasting time will be 04:40 - it will be outputs as 04:40 - Not 4:40 as now. If nearest broadcasting time is 14:41, all works alright..