Need Help Shortening Program and Few Other Things

So I will admit i am asking for help on a homework assignment. I have searched many other help forums and online articles, however I still cannot seem to figure it out.

The prompt for the project is to basically:
1. Ask user if he/she has a rewards card number. If so, is it a valid number. If it is, apply a discount to the total amount spent

2. Check the balance and display the available balance that the user’s account holds.

3. Shop and choose among three different categories: Produce, Meat & Fish, and Beverages which includes:

-Allow the user to select one item at a time along with quantities
-Prompt the user to shop for more items by displaying the categories again
-Calculate the sum of all items chosen
-When user is done shopping, the program should display the total bill, any discounted rate, and the total after a discount has been applied
-Check if the amount is greater than the user account balance, inform the user of an insufficient balance and cancel the order by emptying his/her shopping basket, else display “You are all set!” sentence and prompt
the user to proceed with another transaction.
-In case the order is canceled due to insufficient balance, re-display the menu of choices for the user, and
reset the total bill amount to 0.

I feel like I have a general layout of the program, however I am unsure how to keep a running total throughout the program. I am also a little unsure how to do the boolean expression when prompting for the user's rewards card number.

I would post the program, however after 360 odd lines of code, it takes more than 3 posts to see the whole thing.. I have declared all the food items, and their total prices, and i am using "switch" to go from menu to food items then back to menu.

If I could get any assistance I would greatly appreciate it!

Thanks


This is basically how i have each menu and food item set up.

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
150
151
152
153
154
155
156
 do                      //First menu --------------------------------------------------------------------------
    {
        cout << "Please enter a choice\n"
             << "\n"
             << "Choose 1 to view balance\n"
             << "Choose 2 to shop\n"
             << "Choose 3 to exit\n"
             << "Press return after choice is entered: "
             << "\n";
        cin >> choice1;

        switch(choice1)     // Declare main cases for each menu item------------------------------------------------
        {
        case 1:             // Give user the choice to check his/her balance----------------------------------------
            cout << "balance\n";
            break;

        case 2:             // Give user the choice to shop for groceries or return to menu-------------------------
            cout << "Choose among the three different categories or return to menu\n";

                int choice2;

                do{         // Present secondary menu --------------------------------------------------------------
                    cout << "1-Produce\n"
                         << "2-Meat_and_fish\n"
                         << "3-Beverages\n"
                         << "4-Return_to_menu\n"
                         << "\n";
                    cin >> choice2;
                    cout << "\n";
                    switch(choice2)
                    {
                case 1:    //  Allow user to choose the item name and its quantity in the produce section---------
                    cout << "Please choose which produce item you would like \n" <<"and how much of that item you would like \n";
                    cout << "\n";
                        int fchoice3;

                            do{ // Present item name and its price followed by each case associated with it-----------
                                cout << "1- Bell peppers---$2.49 ea.\n"
                                    << "2- Bananas--59c ea.\n"
                                    << "3- Strawberries---$4.99/lb\n"
                                    << "4- Romaine lettuce---3.99 ea.\n"
                                    << "5- Sweet potatoes---$2.49 ea.\n"
                                    << "6- Garlic bulb---$1.29 ea.\n"
                                    << "7- Lime--79c ea.\n"
                                    << "8- Cucumber---$1.99 ea.\n"
                                    << "9- Red onion---$1.69 ea.\n"
                                    << "10- Return to category menu\n";
                                cin >> fchoice3;
                                cout << "\n";
                                switch (fchoice3)
                                {
                                case 1: cout << "You chose Bell peppers. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod1;

                                        pricep1= prod1*2.49;

                                        cout << "You spent:$" <<pricep1<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";

                                break;

                                case 2: cout << "You chose Bananas. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod2;

                                        pricep2= prod2*.59;

                                        cout << "You spent:$" <<pricep2<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;

                                case 3: cout << "You chose Strawberries. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod3;

                                        pricep3= prod3*4.99;

                                        cout << "You spent:$" <<pricep3<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;

                                case 4: cout << "You chose Romaine Lettuce. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod4;

                                        pricep4= prod4*3.99;

                                        cout << "You spent:$" <<pricep4<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;

                                case 5: cout << "You chose Sweet Potatoes. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod5;

                                        pricep5= prod5*2.49;

                                        cout << "You spent:$" <<pricep5<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;

                                case 6: cout << "You chose Garlic Bulbs. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod6;

                                        pricep6= prod6*1.49;

                                        cout << "You spent:$" <<pricep6<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;

                                case 7: cout << "You chose Lime. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod7;

                                        pricep7= prod7*.79;

                                        cout << "You spent:" <<pricep7<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;

                                case 8: cout << "You chose Cucumber. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod8;

                                        pricep8= prod8*1.99;

                                        cout << "You spent:$" <<pricep8<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;

                                case 9: cout << "You chose Red Onion. \n";
                                        cout << "How many would you like to buy? \n";
                                        cout << "Quantity: ";
                                        cin >> prod2;

                                        pricep9= prod9*1.99;

                                        cout << "You spent:$" <<pricep9<<endl;
                                        cout << "\n" << "To continue shopping select another item number\n";
                                break;
                                }

                              }  while (fchoice3 !=10);

                    break;
Take it up from here:

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
#include <iostream>
#include <string>
#include <vector>

int choice( std::string prompt, std::vector<std::string> options )
{
    std::cout << prompt << '\n' ;
    for( std::size_t i = 0 ; i < options.size() ; ++i )
        std::cout << i+1 << ". " << options[i] << '\n' ;

    int n = 0 ;
    std::cout << "choice? " ;
    std::cin >> n ;
    return n ; // for the moment, assume that n is a valid choice
}

int main()
{
    int choice1 = choice( "Please enter a choice", { "to view balance", "to shop", "to exit" } ) ;

    switch( choice1 )
    {
        case 1:
            // ...
            break ;

        case 2:
        {
            int category = choice( "Choose among the three different categories",
                                   { "Produce", "Meat and fish", "Beverages", "Return to menu" } ) ;

            switch(category)
            {
                case 1 :
                {
                    std::vector<std::string> items =
                    {
                        "Bell peppers---$2.49 ea.",
                        "Bananas--59c ea.",
                        "Strawberries---$4.99/lb",
                        "Romaine lettuce---3.99 ea.",
                        "Sweet potatoes---$2.49 ea.",
                        "Garlic bulb---$1.29 ea.",
                        "Lime--79c ea."
                    };
                    int i = choice( "Please choose which produce item you would like", items ) ;

                    --i ; // vector indices are zero based
                    std::cout << "You chose " << items[i] << "\nHow many would you like to buy? " ;
                    int quantity ;
                    std::cin >> quantity ;
                    const std::vector<double> prices = { 2.49, 0.59, 4.99, 3.99, 2.49, 1.29, 0.79 } ;
                    double amount = quantity * prices[i] ;
                    std::cout << "you spent $" << amount << '\n' ;
                }
            }
        }
    }
}
What do you mean by total ? Is it how much the user need to pay for all of the item before discount ?
For that boolean is it like this
1
2
3
4
if(rewards_card){
  if(card_num=123456) discount=//idk
  else cout<<"invalid card number"
}else discount=0
Topic archived. No new replies allowed.