***How Can I Loop Interval Number Of Times ***

Team, I block commented at the bottom kind of what I need to see.
Here's where I am lost - I know how to do a do, while and an if loop.
But I'm confused on how to the loop number of interval times.
Any Idea?
I will obviously input multiple variables and append all this into a CSV.
This chunk of code I'm having an issue with.

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
 #include <iostream>
using namespace std;

int main()
{
int start_time_hh;
int start_time_mm;
int start_time_ss;
int start_month;
int start_day;
int start_year;
int dd_interval;

cout << "What Is The Date? - In MM/DD/YY Format:" << "\n";
char sep;
cin  >> start_month >> sep >> start_day >> sep >> start_year;
cout << "How Many Days Would You Like This To Occur? - XXX Format:" << "\n";
cin  >> dd_interval;
cout << "What Is The Time Of This Event? - In HH:MM:SS Format:" << endl;
cin  >> start_time_hh >> sep >> start_time_mm >> sep >> start_time_ss;

/*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
*/

}
From the start time, end time and periodicity you'll know how many times the loop needs to run and with that information you can use std::this_thread::sleep_for()
http://www.cplusplus.com/reference/thread/this_thread/sleep_for/
I will jump over to that topic and have a look - is there a way you could display it for a dummy like me? If you have time that is.
here is a stylized outline with some comments, see if this on the lines of what you might need:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <chrono>     // std::chrono::milliseconds
#include <thread>   //std::this_thread::sleep_for

int main()
{
    std::this_thread::sleep_for (std::chrono::seconds(5));
    //the initial sleep_for period would be determined by the difference b/w current time and the future start time

    for (size_t i = 0; i < 10; ++i)
    //the number of times to loop would depend on the difference b/w future start and end times and the periodicity
    {
        std::cout << "hello world\n";
        std::this_thread::sleep_for (std::chrono::seconds(1));
    }
}
Hi, shycas2008,
I’m likely to be totally misunderstanding you question, but... Are you just asking for a strategy to increment the day of a date, keeping into account months, years, leap years...?
If so, please have a look to the following example.
It’s far from being optimized and you can easily find better ones googling around, but it’s based on your code.
If I got the wrong end of the stick, just ignore my post :-)
Please, consider the idea of writing your own class to manage these kind of problems, because a date can definitely being considered a different type.
Also: if you need to rely on your solution to a professional level, you should consider take advantage of the ready made functions in <ctime>.
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;
}

Topic archived. No new replies allowed.