HELP void function

I have been working on this program for a couple of weeks now and am now behind in my online class. My professor is not answering any of my emails and I don't know what to do. I know the program is kind of a mess, but I am trying...I don't know why my void function won't read through after I compile I don't know what is missing. Thanks for any help

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

#include <iostream>      // input/output declarations
#include <iomanip>       // i/o manupulator declarations
using namespace std;


void checks (double checkamount, double& balance, double& servicecharges);

int main ()    
{
   char command;          //transaction type
   double check;          //check amount
   double deposit;          //deposit amount
   double nbal;          //new balance
   double bbal;          //begining balance
   double ebal;          //ending balance
   const double charge = .25;        //service charge
   const double underbalcharge = 5.00;
   const double nsf = 25.00;
   double total;
   double ntotal;
   int count;
   
//  Set up floating point output format
	cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);

//  Type of program
    cout <<"Checkbook Balancing Program\n";
    
    
//  Get begining banance from the user
cout << "Enter the begining balance: \n";
     cin  >> bbal;
     total = .00;
     
     //  Display User Commands     
     cout <<"Commands:\n";
     cout <<"C - process a check\n";
     cout <<"D - process a deposit\n";
     cout <<"E - end the program\n";
     
     do    //start do loop
     {
   
//  Get transaction type from user

    cout <<"Enter a Transcation Type and Transaction Amount: ";
    cin >> command, check;
    
    if (command == 'c' || command == 'C')
    {    
         cin >> command;
       checks (check, bbal, total);
    } 
       
        
    
       else 
            if (command == 'd' || command == 'D')
       {       
       
            cin >> deposit;
       
            if (deposit > 0)
            {
            cout <<"Processing deposit for $ " <<deposit<< endl;
            nbal = bbal+deposit;
            cout <<"Balance is $ " <<nbal<< endl;  
           
            
                 if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                 nbal = bbal - underbalcharge;
                 } 
                 cout <<"Total service charges: $ "<<total<< endl;
            }
            else 
            cout <<"Transaction must be a positive amount" << endl;
       }    
      
       else 
            if (command == 'e' || command == 'E')
       {
             
       cout <<"Processing End of Month \n";
       ebal = nbal - total;
       cout <<"Final Balance is $ " <<ebal<< endl;
       
             
       
       }
         else
       {
       cout <<"Invalid command.\n";
       cout <<"Please enter a Transaction command\n";
       cout <<"C - process a check\n";
       cout <<"D - process a deposit\n";
       cout <<"E - end the program\n"; 
       }
       
     } while (bbal > 0);
      
      
 system ("PAUSE");
 return 0;
}


void checks (double checkamount, double& balance, double& servicecharges)
{
                //check amount
      double nbal;          //new balance
               //begining balance
      double ebal;          //ending balance
      const double charge = .25;        //service charge
      const double underbalcharge = 5.00;
      const double nsf = 25.00;
      double total;
      double ntotal;
      int count;
      double servicecharge;
   
       if (checkamount > 0)
       {
       cout <<"Processing check for $ " <<checkamount<< endl;
       nbal = balance-checkamount;
       cout <<"Balance is $ " <<nbal<< endl;   
       cout <<"Service charge : $.25 for a check\n";
      
             if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                 nbal = nbal - underbalcharge;
                 total = total + charge + underbalcharge;
                 } 
                      if (nbal < 0)
                 { 
                 cout <<"Service charge : $25.00 Insufficient Funds\n";
                 nbal = nbal - nsf;
                 servicecharge = total + charge + underbalcharge + nsf;
                 cout <<"Total service charges: $ "<<servicecharge<< endl;
                 } 
                 else 
                 cout <<"Total service charges: $ "<<total<< endl;
        }         
                 else 
                 cout <<"Transaction must be a positive amount" << endl;
       
}
First, you're asking for a transaction type and amount to be entered at one time.
1
2
cout <<"Enter a Transcation Type and Transaction Amount: ";
    cin >> command, check;
You ought to change your cin >> statement to look like this: cin >> command >> amount; You will have to creat the variable "amount"
next, right after you get that information, you're asking for more input in your if statements:
1
2
3
4
5
if (command == 'c' || command == 'C')
    {    
         cin >> command;
       checks (check, bbal, total);
    } 
get ride of that cin >> command call your checks function with checks(amount, bbal, total);You have something similar after the deposit if statement:
1
2
3
4
5
6
    if (command == 'd' || command == 'D')
       {       
       
            cin >> deposit;
       
            if (deposit > 0)
get rid of that cin >> deposit; part and instead use your amount variable which should have the value you need, assuming it was entered at your command line like it was a check... (just following your program's input instructions). That much will get you into your "void function" with more success for you to debug further.... ask if you have questions.
Last edited on
Thanks that helped so much. Another question. When I am trying to get the service charges to update they don't I get a service charge of .25 everytime. Why is it not updating?
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
if (checkamount > 0)
       {
       cout <<"Processing check for $ " <<checkamount<< endl;
       nbal = balance-checkamount;
       cout <<"Balance is $ " <<nbal<< endl;   
       cout <<"Service charge : $.25 for a check\n";
      
             if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                 nbal = nbal - underbalcharge;
                 nservicecharge = servicecharge + charge + underbalcharge;
                 } 
                 if (nbal < 0)
                    { 
                    cout <<"Service charge : $25.00 Insufficient Funds\n";
                    nbal = nbal - nsf;
                    nservicecharge = servicecharge + charge + underbalcharge + nsf;
                    cout <<"Total service charges: $ "<<nservicecharge<< endl;
                    } 
                 else 
                 nservicecharge = servicecharge + charge;
                 cout <<"Total service charges: $ "<<nservicecharge<< endl;
        }         
        else 
        cout <<"Transaction must be a positive amount" << endl;
       
}
I see where you tell the user they have a $.25 service charge for the check. But where in your program are you taking it out of the account balance? Remember you need to subtract "charge" from "nbal" at some point. What you've been doing is adding "charge" to your "nservicechage" variable so you can display the amount you wanted to charge, even though you never actually charge it from the balance.
I know I have to subtract it from the balance, but my assignment has me doing that later in the program. What I am having trouble with is adding the service charges. I changed service charge to
double servicecharge = 0.00 hoping that would work, but it doesn't either. I can't get my service charge to increment correctly. It is as if it is starting over each time the loop runs. How can I fix that and why is it happeing?
Please post your code again so I can see what's changed and try to run it.
Notice you have a parameter called servicecharges (with an 's' on the end) for your void function, but you declare one just called servicecharge and you never use the one with the 's' on the end... which is the one you have passed by reference so that it can go back to the function that called it.
I really appreciate the help
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
//******************************************************************
// Assignment 1 - I/O, Sums and Products
// Programmer: Christy Sylvest
// Completed : 01/26/08
// Status    : Complete
//
// This program computes the sum, average and product of three numbers
//entered by the user.
//******************************************************************



#include <iostream>      // input/output declarations
#include <iomanip>       // i/o manupulator declarations
using namespace std;


void checks (double checkamount, double& balance, double& servicecharges);

void deposits (double depositamount, double& balance);

int main ()    
{
   char command;          //transaction type
   double amount;          //check amount
   double deposit;          //deposit amount
   double nbal;          //new balance
   double bbal;          //begining balance
   double ebal;          //ending balance
   const double charge = .25;        //service charge
   const double underbalcharge = 5.00;
   const double nsf = 25.00;
   double total;
   double ntotal;
   int count;
   
//  Set up floating point output format
	cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);

//  Type of program
    cout <<"Checkbook Balancing Program\n";
    
    
//  Get begining banance from the user
cout << "Enter the begining balance: \n";
     cin  >> bbal;
     total = .00;
     
     //  Display User Commands     
     cout <<"Commands:\n";
     cout <<"C - process a check\n";
     cout <<"D - process a deposit\n";
     cout <<"E - end the program\n";
     
     do    //start do loop
     {
   
//  Get transaction type from user

    cout <<"Enter a Transcation Type and Transaction Amount: ";
    cin >> command >> amount;
    
    if (command == 'c' || command == 'C')
    {    
         
       checks (amount, bbal, total);
    } 
       
        
    
       else 
            if (command == 'd' || command == 'D')
       {       
       
           
       
            if (deposit > 0)
            {
            cout <<"Processing deposit for $ " <<deposit<< endl;
            nbal = bbal+deposit;
            cout <<"Balance is $ " <<nbal<< endl;  
           
            
                 if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                 nbal = bbal - underbalcharge;
                 } 
                 cout <<"Total service charges: $ "<<total<< endl;
            }
            else 
            cout <<"Transaction must be a positive amount" << endl;
       }    
      
       else 
            if (command == 'e' || command == 'E')
       {
             
       cout <<"Processing End of Month \n";
       ebal = nbal - total;
       cout <<"Final Balance is $ " <<ebal<< endl;
       
             
       
       }
         else
       {
       cout <<"Invalid command.\n";
       cout <<"Please enter a Transaction command\n";
       cout <<"C - process a check\n";
       cout <<"D - process a deposit\n";
       cout <<"E - end the program\n"; 
       }
       
     } while (bbal > 0);
      
      
 system ("PAUSE");
 return 0;
}


void checks (double checkamount, double& balance, double& servicecharges)
{
                //check amount
      double nbal;          //new balance
               //begining balance
      double ebal;          //ending balance
      const double charge = .25;        //service charge
      const double underbalcharge = 5.00;
      const double nsf = 25.00;
      double ntotal;
      int count;
      double servicecharge = 0.00;
      double nservicecharge;
      
      
       if (checkamount > 0)
       {
       cout <<"Processing check for $ " <<checkamount<< endl;
       nbal = balance-checkamount;
       cout <<"Balance is $ " <<nbal<< endl;   
       cout <<"Service charge : $.25 for a check\n";
      
             if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                 nbal = nbal - underbalcharge;
                 servicecharges = servicecharge + charge + underbalcharge;
                 } 
                 if (nbal < 0)
                    { 
                    cout <<"Service charge : $25.00 Insufficient Funds\n";
                    nbal = nbal - nsf;
                    servicecharges = servicecharges + charge + underbalcharge + nsf;
                    cout <<"Total service charges: $ "<<servicecharges<< endl;
                    } 
                 else 
                 servicecharges = servicecharge + charge;
                 cout <<"Total service charges: $ "<<servicecharges<< endl;
        }         
        else 
        cout <<"Transaction must be a positive amount" << endl;
       
}
I think this code is working better. See if you can find more bugs.
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
#include <iostream>      // input/output declarations
#include <iomanip>       // i/o manupulator declarations

using namespace std;


void checks (double checkamount, double& balance, double& servicecharges);

void deposits (double depositamount, double& balance);

int main ()    
{
   char command;          //transaction type
   double amount;          //check amount
   double deposit;          //deposit amount
   double nbal=0;          //new balance
   double bbal;          //begining balance
   double ebal;          //ending balance
   const double charge = .25;        //service charge
   const double underbalcharge = 5.00;
   const double nsf = 25.00;
   double total=0;
   double ntotal;
   int count;
   
//  Set up floating point output format
	cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);

//  Type of program
    cout <<"Checkbook Balancing Program\n";
    
    
//  Get begining banance from the user
cout << "Enter the begining balance: \n";
     cin  >> bbal;
     nbal = bbal;                                         // ***
     total = 0.00;
     
     //  Display User Commands     
     cout <<"Commands:\n";
     cout <<"C - process a check\n";
     cout <<"D - process a deposit\n";
     cout <<"E - end the program\n";
     
     do    //start do loop
     {
   
//  Get transaction type from user

    cout <<"Enter a Transaction Type: ";                     // ***
    cin >> command;
    
    if (command == 'c' || command == 'C')
    {    
       cout << "Enter check amount: ";                       // ***
       cin >> amount;                                        // ***
       checks (amount, nbal, total);                         // ***
    } 
       
        
    
       else 
            if (command == 'd' || command == 'D')
       {       
            cout <<"Enter deposit amount: ";                // ***
            cin >> deposit;                                 // ***
           
       
            if (deposit > 0)
            {
            cout <<"Processing deposit for $ " <<deposit<< endl;
            nbal = nbal + deposit;                                  // ***
            cout <<"Balance is $ " <<nbal<< endl;  
           
            
                 if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                 total = total + underbalcharge;                             // ***
                  
                 cout <<"Total service charges: $ "<<underbalcharge<< endl;
                 }
            }
            else 
            cout <<"Transaction must be a positive amount" << endl;
       }    
      
       else 
            if (command == 'e' || command == 'E')
       {
             
       cout <<"Processing End of Month \n";
       cout <<"Your balance at the end of the month was: " << nbal << endl;
       ebal = nbal - total;
       cout <<"You total service charges for the month is: " <<total<< endl;    // ***
       cout <<"Final Balance is $ " <<ebal<< endl;
       system("pause");                                    // ***
       return 0;
       
             
       
       }
         else
       {
       cout <<"Invalid command.\n";
       cout <<"Please enter a Transaction command\n";
       cout <<"C - process a check\n";
       cout <<"D - process a deposit\n";
       cout <<"E - end the program\n"; 
       }
       
     } while (bbal > 0);
      
      
 system ("PAUSE");
 return 0;
}


void checks (double checkamount, double& balance, double& servicecharges)
{
                //check amount
      double nbal;          //new balance
               //begining balance
      double ebal;          //ending balance
      const double charge = .25;        //service charge
      const double underbalcharge = 5.00;
      const double nsf = 25.00;
      double ntotal;
      int count;
      double servicecharge = 0.00;
      double nservicecharge;
      
      
       if (checkamount > 0)
       {
       cout <<"Processing check for $ " <<checkamount<< endl;
       nbal = balance-checkamount;
       cout <<"Balance is $ " <<nbal<< endl;   
       cout <<"Service charge : $.25 for a check\n";
       servicecharges = servicecharges + charge;                      // ***
      
             if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                // nbal = nbal - underbalcharge;
                 servicecharges = servicecharges + underbalcharge;     // ***
                 } 
                 if (nbal < 0)
                    { 
                    cout <<"Service charge : $25.00 Insufficient Funds\n";
            //  nbal = nbal - nsf;
                    servicecharges = servicecharges + nsf;               // ***
                    cout <<"Total service charges: $ "<<servicecharges<< endl;
                    } 
            //  else
           //  servicecharges = servicecharge + charge;
                 cout <<"Total service charges: $ "<<servicecharges<< endl;
        }         
        else 
        cout <<"Transaction must be a positive amount" << endl;
        balance = nbal;                                                // ***
}


I have made a number of changes, and I tried to mark them with the comments // *** so you can review them.
I think I was able to understand how you wanted the program to work, so I didn't change the way it functions; at least I tried not to.
Ok I think I am understanding better, but I get an error when I add a void deposit function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void deposits (double depositamount, double& balance)
}

     double nbal;
     double bbal;
     
        if (deposit > 0)
        {
        cout <<"Processing deposit for $ " <<depositamount<< endl;
        nbal = bbal+depositamount;
        cout <<"Balance is $ " <<nbal<< endl;  
        }
        else 
        cout <<"Transaction must be a positive amount" << endl;
    


Dev says it expects a ";" before the first "}" why?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void deposits (double depositamount, double& balance)
}    // this needs to be an opening brace {

     double nbal;
     double bbal;
     
        if (deposit > 0)
        {
        cout <<"Processing deposit for $ " <<depositamount<< endl;
        nbal = bbal+depositamount;
        cout <<"Balance is $ " <<nbal<< endl;  
        }
        else 
        cout <<"Transaction must be a positive amount" << endl;
} // add a closing brace it this is the end of your function 
Thanks, that was a stupid mistake. I totally couldn't see it.
Could this boolean variable work? if I want the 5 lowbalance charge to only be charged once for the month if the balance goes under 800? this is 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
void checks (double checkamount, double& balance, double& servicecharges)
{
                
      double nbal;          //new balance
      const double charge = .25;        //service charge
      const double underbalcharge = 5.00;
      const double nsf = 25.00;
      double ntotal;
      int count;
      double servicecharge = 0.00;
     
      
      
       if (checkamount > 0)
       {
       cout <<"Processing check for $ " <<checkamount<< endl;
       nbal = balance-checkamount;
       cout <<"Balance is $ " <<nbal<< endl;   
       cout <<"Service charge : $.25 for a check\n";
       servicecharges = servicecharges + charge;                      // ***
      
             if (nbal < 800.00)
                 { 
                 cout <<"Service charge : $5.00 Balance below $800.00\n";
                // nbal = nbal - underbalcharge;
                
                 servicecharges = servicecharges + underbalcharge;
                  
                      // ***
                 } 
                 if (nbal < 0)
                    { 
                    cout <<"Service charge : $25.00 Insufficient Funds\n";
            //  nbal = nbal - nsf;
                    servicecharges = servicecharges + nsf;               // ***
                    cout <<"Total service charges: $ "<<servicecharges<< endl;
                    } 
            //  else
           //  servicecharges = servicecharge + charge;
                 cout <<"Total service charges: $ "<<servicecharges<< endl;
        }         
        else 
        cout <<"Transaction must be a positive amount" << endl;
        balance = nbal;                                                // ***
}
Topic archived. No new replies allowed.