Accumulator and Count keeps throwing back junk.

I have to write a program that asks the user to input which type of gym membership they want, and how many months they want to join. The program is supposed to count the months and calculate the totals along with the months at the prompt/selection of Exit. I can't seem to get my arguments in the function correct, so the program does not accumulate the total or the months, and throws out junk. This is my first time using a switch loop instead of the if/else. It should have the option of: Adult, Family, Student, & Senior. I only put the Adult up, because this is the only one that I have made the adjustment to thus far. This is an example of what I have:

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

using namespace std;

//function prototypes
void welcome();
void splash();
void billSummary(int,const double,string);
int summary(int,double);
int menu();
int getNumber();

//variables
int count = 0;
double total = 0;
//enumerator
enum{Adult = 1, Family, Student, Senior, Exit}; 
         
//global constants
const double TAX_RATE = 0.075;
const double ADULT = 50;
const double FAMILY = 75;
const double STUDENT = 30;
const double SENIOR = 35;

int main(int argc, char *argv[])
{
    int number;
    int month, adult, family, student, senior, choice;

    //multiple variable statement
    adult = family = student = senior = 0;
    
    //function calls
    splash();
    welcome();
    do
    {      
        choice = menu();
        int count;  
        
        system("CLS");
        cout << down12;
        switch (choice)
        {
               case Adult:
                    do
                    {
                         system("CLS");
                         count += 1;                         
                         number = getNumber();
                         total += number;
                    }while(month < 0);
                    number;
                    billSummary(number,ADULT,"Adult");
                    break;
               case Exit: 
                    cout << over3 
                         << "You selected EXIT. Have a nice day!" << endl;
                    summary(count,total);                                                       
                    break;
               default:
                    cout << over3 << choice 
                         << " is an invalid menu option!!! " << endl
                         << down1 << over3 <<"Please try again." << endl;
                    cout << down10;                                                     
        }
        system("PAUSE");            
    }while(choice != Exit);
    return EXIT_SUCCESS;
}
int getNumber()
{
    int number;          
    
    system("CLS");
    cout << down10 << over3 << "How many months do you want to join? ";
    cin >> number;
    while(number < 0)
    {
         system("CLS");
         cout << down10 << over3 << number << " is invalid!" << endl;
         cout << over3 << "How many months do you want to join? ";
         cin >> number;             
    }
    return number;
    system("PAUSE");
}
int menu()
{
    //input section 

    int choice;
    
    system("CLS");
    cout << down5 
         << over3 << "/----------------------------\\ " << endl
         << over3 << "||    Gym Membership Menu   ||" << endl
         << over3 << "||__________________________||" << endl
         << over3 << "||**************************||" << endl
         << over3 << "|| \t1. Adult            ||" << endl
         << over3 << "|| \t2. Family           ||" << endl
         << over3 << "|| \t3. Student          ||" << endl
         << over3 << "|| \t4. Senior           ||" << endl
         << over3 << "|| \t5. Exit             ||" << endl             
         << over3 << "\\----------------------------/ " << endl;
    cout << down1 << over4 << "Your Choice: ";
    cin >> choice;
    
    return choice;
}
void billSummary(int months,double cost,string type)
{
    //local variables
    double subtotal,tax,total;
        
    //processing
    subtotal = months * cost;
    tax = subtotal * TAX_RATE;
    total = subtotal + tax;

    cout << showpoint << setprecision(2) << fixed;
    
    //output section - totals
    system("CLS");
    cout << setprecision(2) << fixed;
    cout << down8;
    cout << over3 << type << " Membership Summary Bill " << endl
         << over3 << "---------------------------------" << endl
         << over3 << " Months of Membership: " << setw(7) << months << endl 
         << over3 << " Monthly Fee:         $" << setw(7) << cost << endl
         << over3 << " Subtotal:            $" << setw(7) << subtotal << endl
         << over3 << " Tax:                 $" << setw(7) << tax << endl
         << over3 << "---------------------------------" << endl
         << over3 << " Total:               $" << setw(7) << total << endl                         
         << down8;       
}
int summary(int months,double total)
{
    int cost, number, adult, family, student, senior;
    int count = 0;
    double totalMonths, totalFees;
    total = cost * months;
    months = count += number;
    totalMonths = months;
    totalFees += total;
    system("CLS");
    cout << down10
         << down3 << over3 << "ADULT\tFAMILY\tSTUDENT\tSENIOR" << endl;
    cout << over3 << "-----\t------\t-------\t------" << endl;
    cout << over3 << setw(3) << adult << "\t" << setw(4) << family << "\t" 
         << setw(4) << student << "\t" << setw(4) << senior << endl;
    cout << down3 << over3 << "Total Months: " << count << endl;
    cout << down3 << over3 << "Total Fees: " << total << endl;
    cout << down12;               
}

Previously, I thought it might have been because I had the summary function as a void summary(), instead of an int summary(). I feel that I have possibly passed too many arguments, but I'm not sure where I should omit, or where I should add. Can anyone give me some guidance as to what I am doing incorrectly?
At first glance it looks like it's spitting out garbage because you're not initializing your variables in the summary function.

1
2
3
4
5
6
int summary(int months,double total)
{
    int cost, number, adult, family, student, senior;  // <- cost declared here, but not assigned
    int count = 0;
    double totalMonths, totalFees;
    total = cost * months;  // <- cost used here 


Since you never gave 'cost' a value, it's filled with random junk, therefore 'total' is going to have random junk, as is pretty much everything else defined in your summary function.

EDIT:

You actually have this problem in several places.

In the summary function, all of the below variables are used without you having assigned them a meaningful value:
- cost
- number
- totalFees
- senior
- student
- family
- adult

And in main, there are a few as well:
- count (used on line 49 but never initialized)
- month (used on line 52 but never initialized)
Last edited on
Okay, thank you very much. I will apply these changes, and see if that makes a difference in my outcome!
Topic archived. No new replies allowed.