Help - Void functions with bool returns

So, I'm trying to get the printReport function to display the specified outputs using the pre-established values of the bool variables. For example if you input "1" continue, the input "0800", you should get display output from the first three pills, but not the Decongestant as its bool value is false. This program returns all output dispays as if they where all true, like it ignores the bool values established by the other functions.

Any ideas?

Also, I was unable to get the functions to recognize int variables for the medTime user input, any thoughts on why the following functions didn't like int as an input versus string?

void ironPill(string, bool&); // Function Prototype.

void antibioticPill(string, bool&); // Function Prototype.

void aspirinPill(string, bool&); // Function Prototype.

void decongestantPill(string, bool&); // Function Prototype.

Thanks for the help as this is my first post on this forum.

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <string>

using namespace std;

// Functions Used.
void ironPill(string, bool&);		    // Function Prototype.

void antibioticPill(string, bool&);     // Function Prototype.

void aspirinPill(string, bool&);        // Function Prototype.

void decongestantPill(string, bool&);   // Function Prototype.

void printReport(bool, bool, bool, bool);               // Function Prototype.

bool goPrintironPill;

bool goPrintantibioticPill;

bool goPrintaspirinPill;

bool goPrintdecongestantPill;

int proceed;

int hourCount;

int clock;

string medTime;

int main (){

cout << "Good morning, are ready for your pill schedule. Enter 1 to continue: " << endl;
cin >> proceed;

if (proceed != 1)
{
    cout << "Enjoy your morning and try again when ready." << endl;
        }
    else
    {
        cout << "Please enter the next nearest hour (e.g., 0800, 1300, 2100, etc): " << endl;
        cin >> medTime;

        ironPill (medTime, goPrintironPill);
        antibioticPill(medTime, goPrintantibioticPill);
        aspirinPill(medTime, goPrintaspirinPill);
        decongestantPill(medTime, goPrintdecongestantPill);

        printReport(goPrintironPill, goPrintantibioticPill, goPrintaspirinPill, goPrintdecongestantPill);

        cout << "Iron Pill is " << goPrintironPill << endl;                     //  Test: to ensure the bool value is correct.
        cout << "Antibiotic Pill is " << goPrintantibioticPill << endl;         //  Test: to ensure the bool value is correct.
        cout << "Aspirin Pill is " << goPrintaspirinPill << endl;               //  Test: to ensure the bool value is correct.
        cout << "Decongestant Pill is " << goPrintdecongestantPill << endl;     //  Test: to ensure the bool value is correct.
}

return 0;

}//End main


void ironPill(string medTime, bool& goPrint)        // Function determines if the enter time is a time required for a pill.
{

if (medTime == "0800" || medTime == "1200" || medTime == "1800")
{
     goPrintironPill = true;
     } // End if.

     else
     {
         goPrintironPill = false;
} // End else.
} // End ironPill.

void antibioticPill(string medTime, bool& goPrint)  // Function determines if the enter time is a time required for a pill.
{

if (medTime == "0400" || medTime == "0800" || medTime == "1200" || medTime == "1600" || medTime == "2000" || medTime == "2400" || medTime == "0000")
{
     goPrintantibioticPill = true;
     } // End if.

     else
     {
         goPrintantibioticPill = false;
} // End else.
} // End antibioticPill.

void aspirinPill(string medTime, bool& goPrint)     // Function determines if the enter time is a time required for a pill.
{

if (medTime == "0800" || medTime == "2100")
{
     goPrintaspirinPill = true;
     } // End if.

     else
     {
         goPrintaspirinPill = false;
} // End else.
} // End aspirinPill.

void decongestantPill(string medTime, bool& goPrint)  // Function determines if the enter time is a time required for a pill.
{

if (medTime == "1100" || medTime == "2000")
{
     goPrintdecongestantPill = true;
     } // End if.

     else
     {
         goPrintdecongestantPill = false;
} // End else.
} // End decongestantPill.


void printReport(bool goPrintironPill, bool goPrintantibioticPill, bool goPrintaspirinPill, bool goPrintdecongestantPill) // Function displays to screen confirmation to take pill.
{
    if (goPrintironPill = 1)
    {
        cout << "Time to take an Iron Pill." << endl;
    } // End if.

        if (goPrintantibioticPill = 1)
    {
        cout << "Time to take an Antibiotic Pill." << endl;
    } // End if.

    if (goPrintaspirinPill = 1)
    {
        cout << "Time to take an Aspirin Pill." << endl;
    } // End if.

    if (goPrintdecongestantPill = 1)
    {
        cout << "Time to take an Decongestant Pill." << endl;
    } // End if.

} // End printReport. 
Lines 17-21: These values are global. That is poor style. The variables should be local to main.

In each of your pill routines, you're passing a bool value by reference, but you not using it. You're using the global value directly. Again poor style.

Lines 124,129,134,139: You're using the assignment operator (=), not the comparison operator (==). You're setting all the variables true, then testing the result.
Thank you for the assistance. I'm sure my style has much to be desired as this is my first programming class, but hopefully it will improve as I progress with my programming.

I tried moving the lines 17, 19, 21, & 23 to inside the main, but the functions failed stating that the moved bool variables had not been assigned. Not sure why that is failing it.

As for the the pill routines, the reference value is being used in the print function to determine if the particular display for each pill needs to be shown. I now need to make a loop that increments an hour, twenty four times to show what pills need to be taken when.

Again, I'm sure there are better ways, but currently I'm not sure what that way is yet.

Thanks again, especially with comparison operator. I feel like such a novice at this.
Topic archived. No new replies allowed.