Clock through 24 hour day.

I'm trying to write a program that runs through a 24 hour day using a counter variable clock. I'm pretty lost...as usual. C++ is just not for me! But, I need the class, so here I am. The program needs to print an hourly table of medications to take at certain times. So far, this is what I have written....

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

//Function Prototypes

void prescriptionSchedule()

int main ()
{
     int clock_t[] = 0;
          
     int ironPill = 0;
     int antibiotic = 0;
     int aspirin = 0;
     int decongestant = 0;
     
     //Request user initiate program.
     
     cout << "To view prescription schedule press any key: " << endl;
     char start = _getch();
     
          for() 
          {
                prescriptionSchedule()
                    if(clock_t


It's not even a complete code because I'm not sure how to correctly use the clock function in this problem :/
Last edited on
Info on <chrono>: http://www.cplusplus.com/reference/chrono/
Please explain a bit on what you want the programme to do.

Aceix.
Thanks for the reply.

What I'm trying to do is print a table that tells a patient when to take their medications. So for example, I need to print (relay to the patient) that an ironpill needs to be taken at 0800, 1200, and 1800. There are four medications like this that need to be taken at various times. So I need to use a clock to go through the 24 hour day, and at certain points, print such and such medication to be consumed. I'm looking at the Chrono info page you provided, can I use "time_point" to provide the meds be taken at a specific time? I'm just not sure of the best way to write this kind of program :(
So you want to print the tabla at once(then no need for timing), or print medications at specific times depending on the system time?

Aceix.
Well, honestly I'm kind of confused about what my professor wants. I think the assignment wants me to print the table at once, but if that's the case I'm not sure why he would want me to use a counter variable clock...I think that may be my big confusion as a newbie. Also, I'm running DEVC++ and it doesn't even support chrono so I can't compile and run to seek for errors.....any suggestions on a full featured IDE for a new kid on the block?
This is the assignment verbatim if it helps...

Patients required to take many kinds of medication often have difficulty in remembering when to take their medicine. Given the following set of medications, write a function that prints an hourly table indicating what medication to take at any given hour. Use a counter variable clock to go through a 24- hour day.
Print the table on the following prescriptions.

I may be wrong but it reads like he wants you to use a counter (in a variable) for hours and minutes, then cycle through that and if the time (in your counter) reaches a time stored in your patients data it would list that patients data.

So say 4 patients needed to take some tablets at 4:00, the function would list those 4 patients and what medication they need to take.



Code Blocks, Eclipse or Visual Studio 2013 Express to name a few :)
Thanks a bunch Softrix....I'm gonna make an attempt with your suggestion and likely be back for a question or two....I suck at this stuff!!
Just compiled something. But before, I think your teacher wants you to work with real time. This rough work can give you an idea.

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
#include <iostream>  //as usual basic i/o objects
#include <chrono> //for C++11 time like the seconds() line 32
#include <ctime>  //C time functions--useful
#include <thread>  //for the sleep function line 32

using namespace std;
using namespace std::chrono;  //the C++11 time library namespace

int main() {
	time_t st=time(nullptr);  //set programme startup time
	tm* startTime{localtime(&st)};  //setup a tm structure(for time information based on st(ie: startup time))
	tm timeObj;
	unsigned hr=0,min=0;
		
	cout<<"Enter prescribed hour(24hr clock): ";
	cin>>hr;  //user enters hour 0 - 23
	cout<<"\nEnter prescribed minute: ";
	cin>>min;  //user enters minute 0 - 60
	
	if((hr>=0)&&(hr<=23)&&(min>=0)&&(min<=60)) {  //check
		timeObj=*startTime; //assign timeObj the startup time
		timeObj.tm_hour=hr; //set the hour aspect of the startup time to the user defined one
		timeObj.tm_min=min; //set the minute aspect of the startup time to the user defined one
	
		//time difference in seconds between user defined time and startup time
		double timeDiff=difftime(mktime(&timeObj),st);
		
		if(timeDiff<0.0) {
			cout<<"Time passed!!!"; //tell the user to be careful
		}
		else {
			this_thread::sleep_for(seconds((int)timeDiff)); //wait for truncated-to-int "time difference" seconds
									//this ensures(not effectively) the user is informed on the time
									//the drug must be taken
			cout<<"\a\a\a\a\a\n\nHey!!! Take your drugs NOW!!!\a\a\a\a\a";  //inform
		}
	}
	delete startTime;  //clear stuff
	
	return 0;
}


Some more references:
http://www.cplusplus.com/reference/chrono/
http://www.cplusplus.com/reference/ctime/

HTH,
Aceix.
Last edited on
Use a counter variable clock


I think the counter variable statement would point to a variable or variables to just simulate going through time and list those that fall at the given time for medication... otherwise the professor is going to have a long wait for testing the code <g>

So a variable for hours, and minutes and cycle through them. I did notice it also states "hourly" so do you really need to check minutes.. just cycle hours and have it check each hour if someone needs to take medication.

Again, could be wrong but it certainly looks that way.

Thanks a million for the code Aceix, it definitely helps me understand chrono. I am just so new to all this, and I learn by reading/seeing! I think yall are right, though, that I don't even need chrono...so here's the code I've written so far:

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

//Function Prototypes

void prescriptionSchedule()
{
     int i = 0;                           //Variable assignment to begin counter as time at 0.

     #define WIDTH 10
     #define HEIGHT 5

     int prescription [5][10];                                     //Define array dimensions.
     int ironPill[] = {'\t','\t',800,'\t',1200,'\t',1800};
     int antibiotic = 0;
     int aspirin = 0;
     int decongestant = 0;
     int n,m;

     int ironPillTime;

     //Request user initiate program.

     cout << "To view prescription schedule press any key: " << endl;
     cout << "Take prescription when hour is marked with 'X'" <<endl;
     cout << "\t\t\t0400\t0800\t1100\t1200\t1600\t1800\t2000\t2100\t2400" << endl;

     int main ();
     {
           if (n,m = 0) {
                 cout << "\t"; }
           if (n = 1) {
                 cout << "Iron Pill"; }
           if (n = 2) {
                 cout << "Antibiotic"; }
           if (n = 3){
                 cout << "Aspirin"; }
           if (n = 4) {
                 cout << "Decongestant"; }
           if (m = 1) {
                 cout << "\t0400"; }
           if (m = 2) {
                 cout << "\t\t0800"; }
           if (m = 3){
                 cout << "\t\t\t1100"; }
           if (m = 4) {
                 cout << "\t\t\t\t1200"; }
           if (m = 5) {
                 cout << "\t\t\t\t\t1600"; }
           if (m = 6) {
                 cout << "\t\t\t\t\t\t1800"; }
           if (m = 7) {
                 cout << "\t\t\t\t\t\t\t2000"; }
           if (m = 8) {
                 cout << "\t\t\t\t\t\t\t\t2100"; }
           if (m = 9) {
                 cout << "\t\t\t\t\t\t\t\t\t2400"; }
     }

     prescriptionSchedule();
          for(int time = 0000; time < 2400; time += 100)
          {
               for(i = 0; i < ironPillTime; i++)
                 if(time = ironPill[i])
                   cout << "X" << '\t';

          cout << endl;
          }
int main ();
{
    cout << "Prescription Schedule" << endl;
    prescriptionSchedule();
    return;
}
}


But, I'm getting this error
collect2.exe: error: ld returned 1 exit status
. I have written the code only to include the first set of meds to see if it works before I write it out for the other three meds. Thank yall again for all the help!
closed account (j3Rz8vqX)
Line 28 and 69 .....hmm.....

Not valid?
Check the main function(line 69), and what Dput said.
NOTE: You can have only a single main function.

Aceix.
Last edited on
Topic archived. No new replies allowed.