1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// But I'm confused on how to the loop number of interval times.
/*How Would I Loop (++start_day) by (dd_interval) amount of times - and output the result?
Example -
12/15/17,09:00:00
dd_interval = 12 (User Input)
output desired =
12/15/17,09:00:00
12/16/17,09:00:00
12/17/17,09:00:00
12/18/17,09:00:00
12/19/17,09:00:00
12/20/17,09:00:00
12/21/17,09:00:00
12/22/17,09:00:00
12/23/17,09:00:00
12/24/17,09:00:00
12/25/17,09:00:00
12/26/17,09:00:00
12/27/17,09:00:00
*/
#include <iostream>
struct BasicDate {
int day;
int month;
int year;
};
BasicDate incrementDay(BasicDate tobeincremented);
int main()
{
std::cout << "What Is The Date? - In MM/DD/YY Format: ";
char sep;
BasicDate date;
std::cin >> date.month >> sep >> date.day >> sep >> date.year;
std::cout << "What Is The Time Of This Event? - In HH:MM:SS Format: ";
int start_time_hh, start_time_mm, start_time_ss;
std::cin >> start_time_hh >> sep >> start_time_mm >> sep >> start_time_ss;
std::cout << "How Many Days Would You Like This To Occur? - XXX Format: ";
int dd_interval;
std::cin >> dd_interval;
std::cout << "Starting date: " << date.month << '/' << date.day << '/'
<< date.year << ", " << start_time_hh << ':' << start_time_mm
<< ':' << start_time_ss << std::endl;
std::cout << "\nRepeat for " << dd_interval << " days.\n\n";
for(int i{0}; i<dd_interval; i++) {
date = incrementDay(date);
std::cout << date.month << '/' << date.day << '/' << date.year
<< ", "
<< start_time_hh << ':' << start_time_mm << ':'
<< start_time_ss << std::endl;
}
return 0;
}
BasicDate incrementDay(BasicDate tobeincremented)
{
tobeincremented.day++;
switch(tobeincremented.month) {
case 2:
if(tobeincremented.day == 29) {
if(!tobeincremented.year%4) { // it's not leap
tobeincremented.day = 1;
tobeincremented.month++;
}
} else if(tobeincremented.day == 30) {
tobeincremented.day = 1;
tobeincremented.month++;
}
break;
case 4:
case 6:
case 9:
case 11:
if(tobeincremented.day == 31) {
tobeincremented.day = 1;
tobeincremented.month++;
}
break;
case 12:
if(tobeincremented.day == 32) {
tobeincremented.day = 1;
tobeincremented.month = 1;
tobeincremented.year++;
}
break;
default:
if(tobeincremented.day == 32) {
tobeincremented.day = 1;
tobeincremented.month++;
}
break;
}
return tobeincremented;
}
|