Won't calculate while in loop?

Been on this for hours. It wants to calculate the cost of prescriptions depending on the plan but for some reason, it will only do it after I put in a number over 96 and not if I first enter a correct number. I hope that makes sense. I have a massive headache over this one.. thank you.

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
145
146
147
148
149
  Put the#include <iostream>
#include <cmath>
using namespace std;

main() {
char planA; 
const double PLAN_A_PREMIUM = 10.00;
const double PLAN_A_DEDUCTIBLE = 200.00;
const double PLAN_A_COPAY = 40.00;
double planAYearly;
char planB;
const double PLAN_B_PREMIUM = 25.00;
const double PLAN_B_DEDUCTIBLE = 100.00;
const double PLAN_B_COPAY = 20.00;
double planBYearly = (PLAN_B_PREMIUM*12);
char planC;
const double PLAN_C_PREMIUM = 50.00;
const double PLAN_C_DEDUCTIBLE = 0.00;
const double PLAN_C_COPAY = 0.00;
double planCYearly = (PLAN_C_PREMIUM * 12);
char userChoice{};
double userMeds;
double medCost;
char tryAgain;



cout << "Plan A: ";
cout << endl;
cout << "  Monthly premium: $"<< PLAN_A_PREMIUM<< ".00";
cout << endl;
cout << "  Deductible: $" << PLAN_A_DEDUCTIBLE<< ".00";
cout << endl;
cout << "  Copay: "<< PLAN_A_COPAY<< "%";
cout << endl;

cout << "Plan B:";
cout << endl;
cout << "  Monthly premium: $"<<PLAN_B_PREMIUM<< ".00";
cout << endl;
cout << "  Deductible: $" <<PLAN_B_DEDUCTIBLE<< ".00";
cout << endl;
cout << "  Copay: " << PLAN_B_COPAY << "%";
cout << endl;

cout << "Plan C:";
cout << endl;
cout << "  Monthly premium: $" <<PLAN_C_PREMIUM<< ".00";
cout << endl;
cout << "  Deductible: $"<< PLAN_C_DEDUCTIBLE<< ".00";
cout << endl;
cout << "  Copay: " << PLAN_C_COPAY<< "%";
cout << endl;
cout << endl;


while ((tryAgain = 'Y')||(tryAgain = 'y')){

cout<< "Please select a plan (enter A, B, or C): ";
cin >> userChoice;

if ((userChoice == 'A')||(userChoice == 'a')){
   (planAYearly = (PLAN_A_PREMIUM *12));
   cout << "Plan A will cost: $" <<planAYearly<< ".00 a year";
   
   cout << endl;
   cout << "Please enter the estimated number of prescriptions (0 to 96): ";
   cin >> userMeds;
   
      while (userMeds > 96) {
      cout<< "Sorry, '" <<userMeds << "' is not a valid number of prescriptions, please try again.";
      cout << endl;
      cout << "Please enter the estimated number of presciptions (0 to 96): ";
      cout<< endl;
      cin >> userMeds;
      
      
      
      if (userMeds <= 96){
         (medCost = (userMeds * 40));
      cout << "Plan A cost for "<< userMeds << " prescriptions is $"<< medCost <<".00";
      cout<< endl;
     }
      }
   
  }
   else if ((userChoice == 'B')||(userChoice == 'b')){
   cout << "Plan B will cost: $" <<planBYearly<< " per year.";
   cout << endl;
    cout << "Please enter the estimated number of prescriptions (0 to 96): ";
   cin >> userMeds;
   
      while (userMeds > 96) {
      cout<< "Sorry, '" <<userMeds << "' is not a valid number of prescriptions, please try again.";
      cout << endl;
      cout << "Please enter the estimated number of presciptions (0 to 96): ";
      cout<< endl;
      cin >> userMeds;
      
      
      if (userMeds <= 96){
      (medCost = (userMeds * 45));
      cout << "Plan B cost for "<<userMeds<< " prescriptions is $"<<medCost<<".00";
      cout<< endl;
      }
      }
   }
   else if ((userChoice == 'C')||(userChoice == 'c')){
   cout << "Plan C will cost: $" << planCYearly << ".00 a year";
   cout << endl;
 cout << "Please enter the estimated number of prescriptions (0 to 96): ";
   cin >> userMeds;
   
      while (userMeds > 96) {
      cout<< "Sorry, '" <<userMeds << "' is not a valid number of prescriptions, please try again.";
      cout << endl;
      cout << "Please enter the estimated number of presciptions (0 to 96): ";
      cout<< endl;
      cin >> userMeds;
      
      
      if (userMeds <= 96){
      (medCost = (userMeds * 50));
      cout << "Plan C cost for "<<userMeds<< " prescriptions is $"<<medCost<<".00";
      cout<< endl;

      }
     }
   }
   else {
   cout<< "I am sorry, '"<< userChoice << "' was not recognized, please try again.";
   cout << endl;
   cin >> userChoice;
   }
   
   cout << endl;
   cout << "Would you like to choose another plan?";
   cout << endl;
   cout << "Enter 'Y' or 'N' : ";
   cin >> tryAgain;
   if ((tryAgain =='N')||(tryAgain =='n')){
   cout << endl;
   cout <<"Ok, goodbye.";
   break;
  }
  }

return 0;
} code you need help with here.
your compiler should have warned you about = vs ==
line 57.
that means you will need to put a default value on tryagain, OR start using do-while loops.
I also rolled the excessive cout endls into \n on the strings.
consider, instead:
1
2
3
4
5
6
7
8
9
10
       cin >> userMeds; //extra not needed
   
do //while (userMeds > 96) {
{    
      cout << "Please enter the estimated number of presciptions (0 to 96): \n";
      cin >> userMeds;
  if(userMeds > 96)
      cout<< "Sorry, '" <<userMeds << "' is not a valid number of prescriptions, please try 
      again.\n";
}(while userMeds > 96)


and similar for the try again loop, a do-while saves having to 'seed' it with a value to loop one time.
Last edited on
oh, I forgot, your mismatched braces are the problem you asked about.
if usermeds < 96 do be inside the while loop for usermeds > 96.
your mismatched braces are the problem


@Adalaide

You should be able to get a modern editor to do braces for you. If not, the old school way is to type both braces (or anything else that come in pairs () <> []), then go back and fill in between the braces - you will never have mismatched braces again.

if ((tryAgain =='N')||(tryAgain =='n')){

One can make use of the toupper function, then the code is simpler:

if ((tryAgain == 'N')){

You could also improve the indentation, and line up closing braces with the first character of the statement:

1
2
3
4
5
if ((tryAgain =='N')) {
   // cout << endl;  // I like to avoid endl
   cout <<"\nOk, goodbye.\n";
   break;
}

Last edited on
As a first refactor, consider:

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

unsigned getMeds(unsigned max) {
    unsigned userMeds {};

    do {
        cout << "Please enter the estimated number of prescriptions (0 to 96): ";
        cin >> userMeds;
    } while ((userMeds < 1 && userMeds > max) && (cout << "Sorry, '" << userMeds << "' is not a valid number of prescriptions, please try again.\n"));

    return userMeds;
}

int main() {
    constexpr double PLAN_A_PREMIUM {10.00};
    constexpr double PLAN_A_DEDUCTIBLE {200.00};
    constexpr double PLAN_A_COPAY {40.00};
    constexpr double PLAN_B_PREMIUM {25.00};
    constexpr double PLAN_B_DEDUCTIBLE {100.00};
    constexpr double PLAN_B_COPAY {20.00};
    constexpr double PLAN_C_PREMIUM {50.00};
    constexpr double PLAN_C_DEDUCTIBLE {0.00};
    constexpr double PLAN_C_COPAY {0.00};
    constexpr double PLAN_A_COST {40};
    constexpr double PLAN_B_COST {45};
    constexpr double PLAN_C_COST {50};
    constexpr double planAYearly {PLAN_A_PREMIUM * 12};
    constexpr double planBYearly {PLAN_B_PREMIUM * 12};
    constexpr double planCYearly {PLAN_C_PREMIUM * 12};
    constexpr unsigned MaxMeds {96};

    char tryAgain {};

    cout << setprecision(2) << fixed;

    cout << "Plan A: \n";
    cout << "  Monthly premium: $" << PLAN_A_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_A_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_A_COPAY << "%\n";

    cout << "Plan B:\n";
    cout << "  Monthly premium: $" << PLAN_B_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_B_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_B_COPAY << "%\n";

    cout << "Plan C:\n";
    cout << "  Monthly premium: $" << PLAN_C_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_C_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_C_COPAY << "%\n\n";

    do {
        char userChoice {};

        cout << "Please select a plan (enter A, B, or C): ";
        cin >> userChoice;

        if ((userChoice == 'A') || (userChoice == 'a')) {
            cout << "Plan A will cost: $" << planAYearly << " per year\n";

            const auto userMeds {getMeds(MaxMeds)};
            const auto medCost {userMeds * PLAN_A_COST};

            cout << "Plan A cost for " << userMeds << " prescriptions is $" << medCost << "\n";
        } else if ((userChoice == 'B') || (userChoice == 'b')) {
            cout << "Plan B will cost: $" << planBYearly << " per year.\n";

            const auto userMeds {getMeds(MaxMeds)};
            const auto medCost {userMeds * PLAN_B_COST};

            cout << "Plan B cost for " << userMeds << " prescriptions is $" << medCost << "\n";
        } else if ((userChoice == 'C') || (userChoice == 'c')) {
            cout << "Plan C will cost: $" << planCYearly << " per year\n";

            const auto userMeds {getMeds(MaxMeds)};
            const auto medCost {userMeds * PLAN_C_COST};

            cout << "Plan C cost for " << userMeds << " prescriptions is $" << medCost << "\n";
        } else
            cout << "I am sorry, '" << userChoice << "' was not recognized\n";

        do {
            cout << "\nWould you like to choose another plan? (Enter 'Y' or 'N'): ";
            cin >> tryAgain;
        } while ((tryAgain != 'y' && tryAgain != 'Y' && tryAgain != 'n' && tryAgain != 'N') && (cout << "Invalid option\n"));
    } while (tryAgain == 'Y' || tryAgain == 'y');
}

while ((tryAgain != 'y' && tryAgain != 'Y' && tryAgain != 'n' && tryAgain != 'N') && (cout << "Invalid option\n"));

This is another thing I have personal hatred of, the != && != business. Not a fan. If use of std::toupper was made as I mentioned earlier this would be reduced considerably. But the != && != becomes a gigantic mess when there are more than 2 options. I would much rather a switch inside a bool controlled while loop for this. Notice the checks for Y or y appear twice: lines 86 and 87
Yes about toupper() - but this requires some nasty cast stuff - first to unsigned char and then to char so I left it out at this level.

L86/87 yes - L86 checks for valid options. Could have been a .find() check for the char in a string but at this level I doubt the OP has come across string operations. L87 is the terminating condition for the do 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
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
#include <iostream>
#include <iomanip>
#include <cctype>
using namespace std;

unsigned getMeds(unsigned max) {
    unsigned userMeds {};

    do {
        cout << "Please enter the estimated number of prescriptions (0 to 96): ";
        cin >> userMeds;
    } while ((userMeds < 1 && userMeds > max) && (cout << "Sorry, '" << userMeds << "' is not a valid number of prescriptions, please try again.\n"));

    return userMeds;
}

int main() {
    constexpr double PLAN_A_PREMIUM {10.00};
    constexpr double PLAN_A_DEDUCTIBLE {200.00};
    constexpr double PLAN_A_COPAY {40.00};
    constexpr double PLAN_B_PREMIUM {25.00};
    constexpr double PLAN_B_DEDUCTIBLE {100.00};
    constexpr double PLAN_B_COPAY {20.00};
    constexpr double PLAN_C_PREMIUM {50.00};
    constexpr double PLAN_C_DEDUCTIBLE {0.00};
    constexpr double PLAN_C_COPAY {0.00};
    constexpr double PLAN_A_COST {40};
    constexpr double PLAN_B_COST {45};
    constexpr double PLAN_C_COST {50};
    constexpr double planAYearly {PLAN_A_PREMIUM * 12};
    constexpr double planBYearly {PLAN_B_PREMIUM * 12};
    constexpr double planCYearly {PLAN_C_PREMIUM * 12};
    constexpr unsigned MaxMeds {96};

    char tryAgain {};

    cout << setprecision(2) << fixed;

    cout << "Plan A: \n";
    cout << "  Monthly premium: $" << PLAN_A_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_A_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_A_COPAY << "%\n";

    cout << "Plan B:\n";
    cout << "  Monthly premium: $" << PLAN_B_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_B_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_B_COPAY << "%\n";

    cout << "Plan C:\n";
    cout << "  Monthly premium: $" << PLAN_C_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_C_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_C_COPAY << "%\n\n";

    do {
        char userChoice {};

        cout << "Please select a plan (enter A, B, or C): ";
        cin >> userChoice;

        switch (static_cast<char>(toupper(static_cast<unsigned char>(userChoice)))) {
            case 'A':
                {
                    cout << "Plan A will cost: $" << planAYearly << " per year\n";

                    const auto userMeds {getMeds(MaxMeds)};
                    const auto medCost {userMeds * PLAN_A_COST};

                    cout << "Plan A cost for " << userMeds << " prescriptions is $" << medCost << "\n";
                }
                break;

            case 'B':
                {
                    cout << "Plan B will cost: $" << planBYearly << " per year.\n";

                    const auto userMeds {getMeds(MaxMeds)};
                    const auto medCost {userMeds * PLAN_B_COST};

                    cout << "Plan B cost for " << userMeds << " prescriptions is $" << medCost << "\n";
                }
                break;

            case 'C':
                {
                    cout << "Plan C will cost: $" << planCYearly << " per year\n";

                    const auto userMeds {getMeds(MaxMeds)};
                    const auto medCost {userMeds * PLAN_C_COST};

                    cout << "Plan C cost for " << userMeds << " prescriptions is $" << medCost << "\n";
                }
                break;

            default:
                cout << "I am sorry, '" << userChoice << "' was not recognized\n";
                break;
        }

        constexpr const char* valid {"YN"};

        do {
            cout << "\nWould you like to choose another plan? (Enter 'Y' or 'N'): ";
            cin >> tryAgain;
            tryAgain = static_cast<char>(toupper(static_cast<unsigned char>(tryAgain)));
        } while (!strchr(valid, tryAgain) && (cout << "Invalid option\n"));

    } while (tryAgain == 'Y');
}


There's no need to introduce yet another variable - bool for a flag.

instead of : "Choose another ?" , have a quit case in a switch , then the bool controls a single while loop. It's not another variable, but instead of the tryAgain variable.

1
2
3
4
5
6
7
bool Quit {false};
while (!Quit) {
   //switch
   /// ...
   case 'Q': {Quit = true;}

}


Could one make userChoice unsigned char to begin with, thereby getting rid of one of the casts?

Yes - partly to remove one cast. I was also following the OP original 'logic' with the again Y/N prompt as that may be what was expected. But having a quit option on the menu is much neater and more usual.

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

unsigned getMeds(unsigned max) {
    unsigned userMeds {};

    do {
        cout << "Please enter the estimated number of prescriptions (0 to 96): ";
        cin >> userMeds;
    } while ((userMeds < 1 && userMeds > max) && (cout << "Sorry, '" << userMeds << "' is not a valid number of prescriptions, please try again.\n"));

    return userMeds;
}

int main() {
    constexpr double PLAN_A_PREMIUM {10.00};
    constexpr double PLAN_A_DEDUCTIBLE {200.00};
    constexpr double PLAN_A_COPAY {40.00};
    constexpr double PLAN_B_PREMIUM {25.00};
    constexpr double PLAN_B_DEDUCTIBLE {100.00};
    constexpr double PLAN_B_COPAY {20.00};
    constexpr double PLAN_C_PREMIUM {50.00};
    constexpr double PLAN_C_DEDUCTIBLE {0.00};
    constexpr double PLAN_C_COPAY {0.00};
    constexpr double PLAN_A_COST {40};
    constexpr double PLAN_B_COST {45};
    constexpr double PLAN_C_COST {50};
    constexpr double planAYearly {PLAN_A_PREMIUM * 12};
    constexpr double planBYearly {PLAN_B_PREMIUM * 12};
    constexpr double planCYearly {PLAN_C_PREMIUM * 12};
    constexpr unsigned MaxMeds {96};

    cout << setprecision(2) << fixed;

    cout << "Plan A: \n";
    cout << "  Monthly premium: $" << PLAN_A_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_A_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_A_COPAY << "%\n";

    cout << "Plan B:\n";
    cout << "  Monthly premium: $" << PLAN_B_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_B_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_B_COPAY << "%\n";

    cout << "Plan C:\n";
    cout << "  Monthly premium: $" << PLAN_C_PREMIUM << "\n";
    cout << "  Deductible: $" << PLAN_C_DEDUCTIBLE << "\n";
    cout << "  Copay: " << PLAN_C_COPAY << "%\n\n";

    for (unsigned char userChoice {}; userChoice != 'Q';) {
        cout << "Please select a plan (enter A, B, C or Q to quit): ";
        cin >> userChoice;

        switch (userChoice = static_cast<unsigned char>(toupper(userChoice))) {
            case 'A':
                {
                    cout << "Plan A will cost: $" << planAYearly << " per year\n";

                    const auto userMeds {getMeds(MaxMeds)};
                    const auto medCost {userMeds * PLAN_A_COST};

                    cout << "Plan A cost for " << userMeds << " prescriptions is $" << medCost << "\n";
                }
                break;

            case 'B':
                {
                    cout << "Plan B will cost: $" << planBYearly << " per year.\n";

                    const auto userMeds {getMeds(MaxMeds)};
                    const auto medCost {userMeds * PLAN_B_COST};

                    cout << "Plan B cost for " << userMeds << " prescriptions is $" << medCost << "\n";
                }
                break;

            case 'C':
                {
                    cout << "Plan C will cost: $" << planCYearly << " per year\n";

                    const auto userMeds {getMeds(MaxMeds)};
                    const auto medCost {userMeds * PLAN_C_COST};

                    cout << "Plan C cost for " << userMeds << " prescriptions is $" << medCost << "\n";
                }
                break;

            case 'Q':
                break;

            default:
                cout << "I am sorry, '" << userChoice << "' was not recognized\n";
                break;
        }
    }
}
Last edited on
This is another thing I have personal hatred of, the != && != business...

-------
there are so many other ways to do that.
as people said, a switch is nice, the fall-through handles case perfectly.
you can also just multiply or add expressions...
if( !(x == 'y' + x == 'Y' + x == 'n' + x=='N')) //simplified, which can shrink with toupper..

for letters specifically but you can generalize the idea:
bool isvalid[256]{}; //any container will do here. maps, sets, and others can be
//more space efficient, as can vector bool (using just a few bytes for it all)
isvalid['y'] = isvalid['Y'] = isvalid['n'] = isvalid['N'] = true;
... if (!isvalid[input])

mix and match, a bool function with a switch or toupper also results in a simple
if(isvalid(input))
and that is more usual for string/number/larger input validations. You don't want to do this in place every time, you want a little library of validation routines for all the common ones that show up over and over..

and even better: ALL THIS STUFF GOES AWAY once you get to UIs. Its the console I/O that creates most of the woes. Give em a yes and no button and they can't F it up.
Last edited on
Give em a yes and no button and they can't F it up.

Standard WinAPI two-button dialogs are Ok and Cancel.

Never underestimate the ability of a foolish end-user to screw things up, the Universe keeps making more of 'em.
@Adalaide,

I gotta ask: what is your OS and compiler? I see in your initial code you have a "naked" main. No return type.

main must have a return type, and that return type must be int.

https://isocpp.org/wiki/faq/newbie#main-returns-int

Not having a return type should have generated at least a warning. The compilers I use it generates an error.
flags & settings. g++ x.cpp , just like that, will compile almost anything close. void main, naked main, ... at one point I had a double main that another program called with command line args to solve a problem and yes, it got the double out ...
@OP
Once you start introducing lots of repetitive code it is a good idea to see if you can get the computer to do all the work.

So assuming you know about simple arrays (you don't need <vector>'s) then your code can be made a lot simpler and easier to maintain. The last calculations need a bit of work because the co-payment and deductibles aren't being used so far.

( BTW: toupper as-is is OK as long as you are using a normal keyboard. )

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>

using namespace std;

int main()
{
    // SETUP THE PLAN(s) DATA
    char label[]{'A', 'B', 'C'};
    double premium[]{10,25,50};
    double deductible[]{200,100,0};
    double co_pay[]{40,20,0};
    double meds_rate[]{40,45,50}; // ???
    
    int plan_selection{};
    
    char goAgain{'Y'};
    while( goAgain == 'Y')
    {
        char userChoice{};
        while (
               cout<< "Please select a plan (enter A, B, or C) - q to quit: "
               and cin >> userChoice
               and toupper(userChoice) != 'Q'
               )
        {
            switch( toupper(userChoice) )
            {
                case 'A':
                    plan_selection = 0;
                    break;
                    
                case 'B':
                    plan_selection = 1;
                    break;
                    
                case 'C':
                    plan_selection = 2;
                    break;
                    
                case 'Q':
                    break;
                    
                default:
                    std::cout << "Invalid choice\n";
            }
            
           // GET userMeds
            double userMeds{};
            while(
                  cout << "Enter estimated no. of prescriptions (0 to 96): "
                  and cin >> userMeds
                  and (userMeds < 0 or userMeds > 96)
                  )
            {
                cout << "No. prescriptions must be 0-96\n";
            }
            
            
            // DISPLAY CALCULATIONS (probably need some work here)
            cout
            << "Plan " << label[plan_selection] << ":\n"
            << "Monthly premium: $" << premium[plan_selection] << '\n'
            << "Yearly premium: $" << premium[plan_selection] * 12 << '\n'
            << "Deductible: $" << deductible[plan_selection] << '\n'
            << "Copay: " << co_pay[plan_selection] << "%\n"
            << "Meds costs: $" << userMeds * meds_rate[plan_selection] << '\n';
        }
        
        
        std:: cout << "Go again <y/n>? ";
        std::cin >> goAgain;
        goAgain = toupper(goAgain);
    }
    
    
    
    std::cout << "Ok, goodbye.\n";
    return 0;
}
Topic archived. No new replies allowed.