Theatre stats program

I don't know why my age groups are not working.
Here is a sample output.
from ages 31 - 40 there should be 2 people and yet it only counts 1.
Any ideas?

==========================
Theatre Stats Program
==========================
Movie theater snacks available for purchase
==========================================
1 - Soft Drink(such as Coca Cola, ICCEE, Mineral Water etc...)
2 - Popcorn
3 - Nachos
4 - Soft drink & Popcorn
5 - Soft drink & Nachos
6 - Organic and Gluten - free snacks
7 - None
==========================================
please enter age of attendees (-1 to quit): 34
please select the number of the snack item you would like to purchase: 4
please enter age of attendees (-1 to quit): 16
please select the number of the snack item you would like to purchase: 5
please enter age of attendees (-1 to quit): 68
please select the number of the snack item you would like to purchase: 6
please enter age of attendees (-1 to quit): 53
please select the number of the snack item you would like to purchase: 6
please enter age of attendees (-1 to quit): 39
please select the number of the snack item you would like to purchase: 1
please enter age of attendees (-1 to quit): 23
please select the number of the snack item you would like to purchase: 2
please enter age of attendees (-1 to quit): 21
please select the number of the snack item you would like to purchase: 3
please enter age of attendees (-1 to quit): 21
please select the number of the snack item you would like to purchase: 4
please enter age of attendees (-1 to quit): -1

==============================
Theatre Stats Program Results
==============================
The total number of attendees is 8
The average age of the attendees is :34.38
Lowest age was: 16
highest age was: 68


ages 0-18: 1
ages 19-30: 3
ages 31-40: 1
ages 41-60:1
ages 60 and up: 1

Theatre concession stand sales
=========================================

Soft Drink(such as Coca Cola, ICCEE, Mineral Water etc...): 1
Popcorn: 1
Nachos: 1
Soft drink & Popcorn: 2
Soft drink & Nachos: 1
Organic and Gluten - free snacks: 2
None: 0
==========================================

Process returned 0 (0x0) execution time : 43.319 s
Press any key to continue.


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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int  age, age1 = 0, age2 = 0, age3=0, age4=0, age5=0, sum = 0,  counter = 0, snack = 0, low, high;
    int snack1 = 0, snack2 = 0, snack3 = 0, snack4 =0, snack5 = 0, snack6= 0, snack7 = 0;
    double average = 0;

      cout << "==========================" << endl;
      cout << "   Theatre Stats Program  " <<endl;
      cout << "==========================" << endl;





        cout << "Movie theater snacks available for purchase" <<endl;
		cout << "==========================================" << endl;
		cout << "1 - Soft Drink(such as Coca Cola, ICCEE, Mineral Water etc...)"<<endl;
		cout << "2 - Popcorn" << endl;
		cout << "3 - Nachos" << endl;
		cout << "4 - Soft drink & Popcorn" << endl;
		cout << "5 - Soft drink & Nachos" << endl;
        cout << "6 - Organic and Gluten - free snacks" << endl;
		cout << "7 - None"<< endl;
		cout << "==========================================" <<endl;







    cout << "please enter age of attendees (-1 to quit): ";
    cin>>age;


    while (age != -1)
    {

                    if (counter ==0)
                    {
                        high = age;
                        low  = age;
                    }
                    else
                    {
                        if  (age < low &&  age != -1)
                             low = age;

                        if
                            (age > high && age != -1)
                            high = age;
                    }




       cout << "please select the number of the snack item you would like to purchase: ";
       cin>> snack;

       switch(snack)
        {
            case 1:
                    snack1++;
                    break;


            case 2:
                    snack2++;
                    break;


            case 3:
                    snack3++;
                    break;

            case 4:
                    snack4++;
                    break;

            case 5:
                    snack5++;
                    break;

            case 6:
                    snack6++;
                    break;

            case 7:
                    snack7++;
                    break;

            default: cout << "Invalid Input try again and chose from 1 - 7"<<endl;
        }

       counter++;
        sum+= age;
           cout << "please enter age of attendees (-1 to quit): ";
           cin>>age;

                    if (age>=0 && age<=18)
                    {
                        age1++;
                    }

                    if (age>=19 && age<=30)
                    {
                        age2++;
                    }
                    if (age>=31 && age<=40)
                    {
                        age3++;
                    }
                    if (age>=41 && age<=60)
                    {
                        age4++;
                    }
                         if (age>=61)
                    {
                        age5++;
                    }

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

      cout << "==============================" << endl;
      cout << " Theatre Stats Program Results " <<endl;
      cout << "==============================" << endl;





    cout << "The total number of attendees is " << counter << endl;
             average=static_cast<double>(sum)/counter;


    cout << "The average age of the attendees is :" << average << endl;
    cout << "Lowest age was: "  <<  low << endl;
    cout << "highest age was: " << high << endl;
    cout << "                                     "<< endl;
    cout << "                                     "<< endl;



    cout << "ages 0-18: " << age1 <<endl;
    cout << "ages 19-30: " << age2 <<endl;
    cout << "ages 31-40: " << age3 <<endl;
    cout << "ages 41-60:"  << age4 <<endl;
    cout << "ages 60 and up: " << age5 <<endl;
    cout << "                                     "<< endl;


        cout << "Theatre concession stand sales" <<endl;
        cout << "========================================="<< endl;
         cout << "                                     "<< endl;
        cout << "Soft Drink(such as Coca Cola, ICCEE, Mineral Water etc...): " << snack1 <<endl;
		cout << " Popcorn: " << snack2 <<endl;
		cout << "Nachos: " << snack3 <<endl;
		cout << "Soft drink & Popcorn: " << snack4 <<endl;
		cout << "Soft drink & Nachos: " << snack5 <<endl;
        cout << "Organic and Gluten - free snacks: " << snack6<<endl;
		cout << "None: "<< snack7<<endl;
		cout << "==========================================" << endl;






    return 0;


}

Every programmer must be able to know how to debug a program.You can find many tutorials online and debugging is of vital importance when you are making some more complex stuff.Put a breakpoint
somewhere and start looking in a watch window how your variables are changing.Believe me ,you will learn much more about programing if you know how to correctly debug your program.
The problem is line 36. The value is overwritten on line 101.
Topic archived. No new replies allowed.