Stuck in a while Loop

Hi everyone. I am trying to create a program that alerts you when it is a specific time and seem to have gotten through most of the hard stuff yet I am still encountering a problem where I can't get out of a while loop.

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
#include <iostream>
#include <string>
#include <stdio.h>
#include <time.h>

using namespace std;

int main() 
{
	string reminders[10]; // A maximun of 100 reminders
	int times[6][10]; // A maximun of a 100 times (one for each reminder) and 6 stored values for each time (hh:mm:ss)

	bool addReminder = true;
	
	int i = 0;
	while (addReminder == true) 
	{
		addReminder = false;
		
		cout << "Remind me to: ";
		getline(cin, reminders[i]);

		cout << "At this time (eg. hh:mm:ss, using 24 hour clock): ";
		string inputTime;
		getline(cin, inputTime);
		times[0][i] = inputTime[0] - '0'; // Converts inputTime into a int
		times[1][i] = inputTime[1] - '0';
		times[2][i] = inputTime[3] - '0';
		times[3][i] = inputTime[4] - '0';
		times[4][i] = inputTime[6] - '0';
		times[5][i] = inputTime[7] - '0';
		
		i++;
		
		cout << "\nWould you like to add another reminder: ";
		string addTaskChoice;
		cin >> addTaskChoice;
		
		if (addTaskChoice == "Yes" | addTaskChoice == "yes") 
		{
			addReminder = true;
		}
		
		cin.ignore();
	}
	
	int c = 0;
	while (1) 
	{
		cout << "hello"; // To test if this loop has begun
		
		time_t seconds;
		seconds = time(NULL);
		while (seconds > 86400) // Turning time since Jan 1 1970 into seconds since the beginning of the day
		{
			seconds -= 86400;
		}
			
		int inputSeconds = times[0][c] * 36000 + times[1][c] * 3600
		+ times[2][c] * 600 + times[3][c] * 60 + times[4][c] * 10 + times[5][c]; // Turn user inputed time into time since beginning of the day
			
		if (seconds > inputSeconds) // Check if the time is larger than the time inputed
		{
			cout << reminders[c];
		}
		
		if (c < 9)
		{
			c++;
		}
		
		else 
		{
			c = 0;	
		}
		
		sleep(1);
	}
}


This is the output:

1
2
3
4
5
6
Remind me to: Write better C++ Codes
At this time (eg. hh:mm:ss, using 24 hour clock): 23:00:00

Would you like to add another reminder: No

//Note, "hello" is not printed indicating this loop while function hasn't been entered 


Any help as on how to fix this problem or where I am going wrong would be much appreciated! Thank you very much :)
cout << "hello";

This code puts hello into the buffer for output. It does not force that output to happen straightaway. Try this instead:

cout << "hello" << endl;
That works, thank you. However I only put the "hello" in there to test that that while function had started because for some reason, it is still not printing the reminder when the specified time comes around. Would you happen to know why that is?
Would you happen to know why that is?


I know how I would find out. I would start by having it output on screen what time it thinks it is in every loop, and show me the values it is comparing, so I can see why it is not working.
Topic archived. No new replies allowed.