where should I put my running total ?

I cannot figure out where a running total works for my program (new to coding / c++ )

the running total of the user's price, in case they want another oder of pizza when the program loops


Here's the code:


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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
  #include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;


void displayPizzaMenu();

void displaySizeMenu();

int getPizzaChoice();

int getSizeChoice();

void totalprice (int, double);



int main()
{


const double personal = 10.00,  /// aka num 2  
             medium = 14.50,
            large = 19.00,
            extralarge = 23.50;

const int MEAT_CHOICE = 1,
        VEGGIE_CHOICE =2,
        HAWAII_CHOICE =3,
        PHILLY_CHOICE =4,
        BBQ_CHOICE = 5,
        EXIT_CHOICE = 6;

const int PERSONAL_SIZE = 1,
            MEDIUM_SIZE =2,
            LARGE_SIZE =3,
            EXTRA_LARGE =4;

int pizzaChoice; // holds menu choice
int sizechoice; // holds size 
int howMany; //how many they want aka   num 1
double total=0.0;

cout<< setprecision(2)<<fixed<<showpoint;


cout<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<< " Welcome to V's Pizza of West Chester! \n";
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<endl;




do{

displayPizzaMenu ();
getPizzaChoice ();

cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

displaySizeMenu();
getSizeChoice();

sizechoice= getSizeChoice();
switch (sizechoice)
{
case 1:
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<" How many personal pizzas?  ";
cin>>howMany;
cout<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<endl;
cout<< fixed << showpoint << setprecision(2);
cout<< "Your order total is  $";
totalprice(howMany, personal);
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
break;


case 2:
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<" How many medium pizzas?  ";
cin>> howMany;
cout<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<< "Your total price is  $";
cout<< fixed << showpoint << setprecision (2);
totalprice(howMany, medium);
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
break;


case 3:
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<" How many large pizzas?  ";
cin>>howMany;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<< " Your order total is  $";
cout<< fixed << showpoint << setprecision (2);
totalprice(howMany, large);
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
break;

case 4:
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<" How many extra large pizzas?  ";
cin>>howMany;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<< "Your order total is $";
cout<< fixed << showpoint << setprecision (2);
totalprice(howMany, extralarge);
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
break;

    }


} while (sizechoice <= 4);








return 0;

}





void displayPizzaMenu()
{
cout<<"Specialty Pizza Menu \n"
<< "1) Meat Lovers \n"
<< "2) Vegetartian \n"
<< "3) Hawaiian \n"
<< "4) Philly Steak \n"
<< "5) BBQ Chicken \n"
<< "6) Exit Menu \n";
}




void displaySizeMenu()
{
cout<<"Available Sizes and Prices \n"
<<endl
<< "1) 10 Personal       - $10.00 \n"
<< "2) 14 Medium         - $14.50\n"
<< "3) 16 Large          - $19.00\n"
<< "4) 18 Extra Large    - $23.50\n";

}
 



int getPizzaChoice()
{
  int pizzaChoice;
  cout<< "Your choice (1-6)?  ";
  cin>>pizzaChoice;

while (pizzaChoice < 1 || pizzaChoice > 6)
{
cout<< pizzaChoice << " is not a valid choice. Please enter 1-6. \n"; 
cout<< "your choice?   ";
cin>>pizzaChoice;
}
 if ( pizzaChoice == 6)
  {
cout<< " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
<<" Thank you for visiting V's Pizza of West Chester!  Come back Soon!\n"
<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<endl;
  exit(-1);
  }
   pizzaChoice++;
  return pizzaChoice;
}



int getSizeChoice()
{
 int sizechoice;
cout<<" Your Choice (1-4)?   ";
cin>>sizechoice;

if ((sizechoice > 4 ) || (sizechoice < 0))
{
cout<< " please enter a valid choice (1-4)\n";
cin>>sizechoice;
}
return sizechoice;
}

void totalprice (int num1, double num2)
{
cout<<(num1 * num2)<<endl;

}
Last edited on
total of what? on line 121, as an example, you can have runtot+= totalprice; where runtot would be a new variable initialized to zero (above the loop!) and maybe printed on 125 or whatever.
Last edited on

the running total of the user's price, in case they want another order of pizza when the program loops, I don't know how to implement that.


I will try what you recommended, thank you
Last edited on
Somewhat simplified:

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

void displayPizzaMenu();
void displaySizeMenu();
int getPizzaChoice();
int getSizeChoice();
double totalprice(double);

const string line(57, '~');

int main() {
    constexpr double personal {10.00}, medium {14.50}, large {19.00}, extralarge {23.50};

    constexpr int MEAT_CHOICE = 1,
        VEGGIE_CHOICE = 2,
        HAWAII_CHOICE = 3,
        PHILLY_CHOICE = 4,
        BBQ_CHOICE = 5,
        EXIT_CHOICE = 6;

    constexpr int PERSONAL_SIZE = 1,
        MEDIUM_SIZE = 2,
        LARGE_SIZE = 3,
        EXTRA_LARGE = 4;

    int pizzaChoice {};
    double total {};

    cout << setprecision(2) << fixed << showpoint;

    cout << '\n' << line << '\n';
    cout << "Welcome to V's Pizza of West Chester! \n";
    cout << '\n' << line << '\n';

    do {
        displayPizzaMenu();
        pizzaChoice = getPizzaChoice();

        if (pizzaChoice == EXIT_CHOICE) {
            cout << line << "\nThe total price for the order is $" << total
                << "\nThank you for visiting V's Pizza of West Chester!  Come back Soon!\n"
                << line << "\n\n";
        } else {
            cout << line << '\n';

            displaySizeMenu();

            cout << line << '\n';

            switch (getSizeChoice()) {
                case PERSONAL_SIZE:
                    cout << "How many personal pizzas?  ";
                    total += totalprice(personal);
                    break;

                case MEDIUM_SIZE:
                    cout << "How many medium pizzas?  ";
                    total += totalprice(medium);
                    break;

                case LARGE_SIZE:
                    cout << "How many large pizzas?  ";
                    total += totalprice(large);
                    break;

                case EXTRA_LARGE:
                    cout << "How many extra large pizzas?  ";
                    total += totalprice(extralarge);
                    break;
            }

            cout << "The current total of the order is $" << total << '\n' << line << '\n';
        }
    } while (pizzaChoice != EXIT_CHOICE);
}

void displayPizzaMenu() {
    cout << "Specialty Pizza Menu\n\n"
        << "1) Meat Lovers\n"
        << "2) Vegetartian\n"
        << "3) Hawaiian\n"
        << "4) Philly Steak\n"
        << "5) BBQ Chicken\n"
        << "6) Exit Menu\n";
}

void displaySizeMenu() {
    cout << "Available Sizes and Prices\n\n"
        << "1) 10 Personal       - $10.00\n"
        << "2) 14 Medium         - $14.50\n"
        << "3) 16 Large          - $19.00\n"
        << "4) 18 Extra Large    - $23.50\n";
}

int getPizzaChoice() {
    int pizzaChoice {};

    cout << "Your choice (1 - 6)?  ";

    while ((cin >> pizzaChoice) && (pizzaChoice < 1 || pizzaChoice > 6)) {
        cout << pizzaChoice << " is not a valid choice. Please enter 1 - 6.\n";
        cout << "Your choice? ";
    }

    return pizzaChoice;
}

int getSizeChoice() {
    int sizechoice {};

    cout << "Your Choice (1 - 4)? ";

    while ((cin >> sizechoice) && (sizechoice > 4 || sizechoice < 0))
        cout << "Please enter a valid choice (1 - 4)? ";

    return sizechoice;
}

double totalprice(double num2) {
    int howMany {};

    cin >> howMany;

    const double total {howMany * num2};

    cout << line << '\n'
        << "Your order total is $" << total << '\n';

    return total;
}

Last edited on
Topic archived. No new replies allowed.