I've created arrays that consist of the times that certain meds are supposed to be taken. I've voided out most everything just so that I can work on the first array. But, it's not printing anything. It's supposed to print an "X" when the int j is equal to one of the numbers in the array. Any help is greatly appreciated!! Hope I gave enough info.
Ohh. So it's not outputting anything because it's reading ironPillTime as the number of values in the array? How to I make it call to the pointers? I thought that's what the sizeof line did?
I believe you want to continue checking while the largest number hasn't been tested against; which is 1800.
Size of is returning 3, the size of your array:
1 2 3 4 5 6 7 8 9
#include <iostream>
usingnamespace std;
int main ()
{
int ironPill [3] = {800, 1200, 1800};
int ironPillTime = sizeof(ironPill)/sizeof(int);
cout<<sizeof(ironPill)/sizeof(int)<<endl;
return 0;
}
Integer in my unit has a size of 4, and 3 integers would have a size of 12. After dividing my int(4) it would be left with 3.
A non-permanent static-solution may be: for(int j = 0; j < 1800; j += 100)
For a dynamic solution, you should try to determine the largest value within your array of integers and test it against that. for(int j = 0; j < largestValue; j += 100)
In your case, {800, 1200, 1800}, 1800 was the largest value.
#include <iostream>
#include <time.h>
usingnamespace std;
//Function Prototype
class KeepRunning
{public:~KeepRunning() {
system("pause"); }
};
void prescriptionSchedule(void)
{
//Variable assignment to begin counter as time at 0.
int j = 0;
//Establish times for each medicine to be consumed.
int ironPill [3] = {800, 1200, 1800};
int ironPillTime = sizeof(ironPill)/sizeof(int);
cout << "Iron Pill: ";
for(int clock = 0000; clock < 2400; clock += 100)
{
for(int j = 0; j < ironPill[3]; j++)
if(j == ironPill[0])
cout << "\t X";
if(j == ironPill[1])
cout << "\t\t\t\t X";
if(j == ironPill[2])
cout << "\t\t\t\t\t\t X";
}
}
int main ()
{
KeepRunning kr;
cout << "\nTake prescription when hour is marked with 'X'\n" << endl;
cout << "\t\t\tPrescription Schedule\n" << endl;
cout << "\t 0400 0800 1100 1200 1600 1800 2000 2100 2400" << endl;
prescriptionSchedule();
return 0;
}
I should add that I'm trying to call each point of the array at it's value. So, I'm trying to print a certain output for {800, 1200, 1800}. That's why I set
if(j == ironPill[0])
and such. Am I trying to do something that's impossible, or am I just doing it wrong?? :/. This is just not my strong point, so I'm sorry if I'm asking stupid questions!
I'm not really sure how to show you a picture of my output, but it looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Take prescription when hour is marked with 'X'.
Prescription Schedule
0400 0800 1100 1200 1600 1800 2000 2100 2400
Iron Pill: X X X
X X X
X X X
X X X
X X X
X X X
X X X
X X X
etc.
Wow, yeah that helped a lot. I tried that with clock before, but it wasn't compiling so I gave up. Thanks a bunch! Now it's not printing my "0" point of the array for the antibiotics though???