Debugging error ..need assistance

Im having trouble with this program...
It does compile but its not debugging
im trying to get output of it and can't get through
:(

Problem Specification:
The Siegel passaic bank ( address: 100 elm street passaic NJ, telephone number 201-625-1212) has hired you to write a c++ program to calculate a customer service fee for his/her checking account..it should input customer name, starting balance of the account, which package the customer has purchased, and how many checks were written.

create a bill that includes the input information, the checking account fee, and a nwe account balance after the cehcking account fee is subtracted from the starting balance of the account.

Requirements:
Input validation: Be sure the user only selects package A,B,or C. Display an error message if the wrong package is entered and end the program.

Calculation:
Package A: For $9.95 per month, 10 checks are allowed. Additional checks are .20 per cehck.
Package B: For $14.95 per month, 20 checks are allowed. Additional checks are .10 per check.
Package C: For $19.95 per month unlimited number of checks are allowed.

Data:

Bo Peep       $250.50   A    18
Al smith      $350.75   A    15
Jack Horner   $1500.50  B    20
Yellow Banana $200.25   b    45
Sue James     $2000.50  C    10
Lia bean      $375.50   W    15


*Input should be done in Main
*Functions: There should be atleast two functions besides main.


CODES That are compiling but errors in debugging !!


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


// Constants
const double package_a = 9.95;
const double package_b = 14.95;
const double package_c = 19.95;

void inputData(string&, double&, char&, int&) ;         
double feeamount (char,int) ;                                       
void displayOutput(string,double,char,int,double,double);

int main ()
{
	// Local Declarations
    string name;
    int num_checks;
	char package;

	double intial_balance, new_balance, cost_package, fee_total= 0.0;

	//Program statements

	inputData(name,intial_balance, package, num_checks);
	package = toupper (package) ;

	if (package == 'A') //  a=9.95
		cost_package = package_a;
	else if (package=='B') //   b=14.95
		cost_package = package_b;
	else if (package == 'C') // c=19.95  
		cost_package = package_c ;
	else 
	{
		cout<< "\nPlease enter a valid package A, B, or C" <<endl;

		return 0;
	}


	fee_total = feeamount(package,num_checks);

	new_balance= intial_balance -  fee_total;

	// OUTPUT


	displayOutput(name,intial_balance,package, num_checks,cost_package,new_balance) ;
return 0;

}
void inputData(string& name, double& initial_balance, char& package, int& num_checks)
{
	cout<< "\nEnter name: ";
	getline(cin, name);
	cout<< "\nEnter initial balance: ";
	cin>>initial_balance;
	cout<< "\nEnter type of package: ";
	cin>>package;
	cout<< "\nEnter number of checks: ";
	cin>>num_checks;
	return;
}

double feeAmount (char package, int num_checks)
{
	double cost_package, fee_total;
	double fee_checks=0;

	if (package=='A')
	{
	  cost_package = package_a;
		if (num_checks>10)
		{
			 fee_checks= (num_checks -10)*0.2;
		}
		else
			{ fee_total = cost_package + fee_checks;
		}
	}
	else if (package=='B')
	{
		cost_package = package_b;
		if (num_checks>20)
		{
			 fee_checks=(num_checks - 20)*0.1;
		}
		else
		{
		  fee_total = cost_package + fee_checks;
		}
	}
	else
	{
	  cost_package = package_c;
	  fee_total= cost_package;
	}
return fee_total;
}

void displayOutput(string name, double initial_balance, char package, int num_checks,double cost_package, double new_balance)
{
     // Statements  
    cout<<setiosflags(ios::fixed) <<setiosflags(ios::showpoint)
		<<setprecision(2);


cout<<"t\t_____________________________________________\n"
         <<"                                                                                                            \n"
         <<"\t\t            Seigel          Passaic       Bank                                         \n"<<endl<<endl;

cout<<"t\t\Account  summary"<<endl;
cout<<"t\t\------------------------"<<endl<<endl;
cout<<"t\t\Name :  "<<setw(45)<<name   <<  endl;
cout<<"t\t\Inital Balance: "<<setw(21)<<"$"<<initial_balance <<  endl;
cout<<"t\t\package:  "<<setw(35)<<"Package"<<package<< endl;
cout<<"t\t\checks :   "<<setw<<num_checks<<  endl;
cout<<"t\t\fee package: "<<setw(25)<<"$"<<cost_package<< endl;
cout<<"t\t\<<new balance:  "<<setw(25)<<"$"<<new_balance << endl<<endl;


if (new_balance<200)
    cout<<setw(10)<<right<<"\n"<<"\t\tWarning: Balance too low "<< endl;
cout<<"t\t\_________________________________________\n" <<endl<<endl;
return;

}




Please, if possible correct all my mistakes in detail ...i wanna get this program done by today, its really confusing for me!
Any Help?Please??
What runtime errors are you getting? - please post in full.


Do you know how to use the debugger? Saying that it is not debugging tells me you are not sure of what the concept of debugging is.

Debugging means to use a debugging program to step through your code 1 line a t a time, while keeping track of the value variables with a watchlist. In this way you can try to deduce where things go wrong. If you have a debugger in your IDE, it hopefully will be easy. Some IDE's just call a command line debugging program, but others integrate the debugger fully into the GUI.

The command line debuggers are harder to use, but not impossible. There is an article on this site on how to use gdb.

Line 38 should be in the inputData function, not just exit the whole program if it is wrong. return 0; means successful termination - return something else if not.

Line 65 is not necessary for a void function.

I would consider having a struct which holds all the info for one account - that way you can send the struct as a parameter to the displayOutput function, rather than a heap of variables. It also would make the program more scalable if you had multiple accounts, by having a vector of the structs.

Hope this helps.
Hi,

Your program isn't compiling, because you misspelt 'feeamount' which you declared as 'feeAmount'.

By the way, if you put your main() routine at the bottom of the file then you won't have to forward-declare the functions that it is using.

Good luck.

Z
@zlatkoz

By the way, if you put your main() routine at the bottom of the file then you won't have to forward-declare the functions that it is using.


But it is proper practice to do that - so we don't have to scroll down to see what main does. main may not call any or some of the functions defined before it.

Good Work though spotting the spelling error - I was under impression the program was compiling.
Last edited on
Hi TheIdeasMan,

it is proper practice to do that - so we don't have to scroll down to see what main does


Really? Who introduced this rule?

There many reasons why I believe this rule to be wrong.

First, are you really sure that you can figure out what a program does just by looking at its main() routine? Second, if you are going to type all the forward function declarations, is this a good investment of your time? What about having to change them once you have changed the name of the function or its signature? This is not only time consuming but also error prone, as we can see from the present example.
Third, main() should really be in its own file and so should the rest of the application. Thus you wouldn't really have to scroll down to find it.
Four, you would probably also use a make file to gel it all together.
Five, since when the programmers shy away from scrolling down? I don't even notice doing it. Neither do I notice changing screen using alt-tab. If I did I don't think I would have lasted long in this job.

Z
Last edited on


Really? Who introduced this rule?


Well I believe Kernighan & Ritchie - the inventors of the C language. Bjarne Stroustrup the inventor of C++ does it too. Are those suitably big names to drop? It is also very common practice in industry because of that. There probably is a technical reason as to why it helps the compiler as well.

First, are you really sure that you can figure out what a program does just by looking at its main() routine?


You can at least see what functions are called, and as I said sometimes there are functions which aren't being used at the moment.

Second, if you are going to type all the forward function declarations, is this a good investment of your time? What about having to change them once you have changed the name of the function or its signature? This is not only time consuming but also error prone, as we can see from the present example.


That is what copy and paste are for.

Third, main() should really be in its own file and so should the rest of the application. Thus you wouldn't really have to scroll down to find it.


And if you had the functions in another file in a C program, you would still have to declare each function with the extern keyword. One shouldn't just put the functions into a header file and include them, because code in header files is bad news. You could put the declarations of functions and other bits and pieces like const variables in a header, that is what they are for. Then put the function definitions in a .c file.

With C++ programs, it doesn't matter so much because class declarations go in a header, and definitions in a .cpp file. Forward declaration of classes happens all the time in C++.

Four, you would probably also use a make file to gel it all together.


Yes, but that doesn't make any difference as to which files the code is written in, or whether there are declarations, it is more about conditional compilation.

Five, since when the programmers shy away from scrolling down?


Yes, but the program execution starts with main, so a lot of people prefer to start their reading from there, and they do not want to scroll down 500 lines in order to do so.

I guess that this sort of thing comes from newbies reading textbooks, which frequently do not show the best way of doing things.

It will be interesting to see what other people think.


Last edited on
Hi TheIdeasMan,

seeing as you believe that:

this sort of thing comes from newbies reading textbooks, which frequently do not show the best way of doing things.


then stop doing it:

Well I believe Kernighan & Ritchie - the inventors of the C language. Bjarne Stroustrup the inventor of C++ does it too.


:-)

Z

Not all text books are bad, the ones written by the inventors of the language are better than average IMHO.

The problem with writing text books is that they often need to be fairly simple to demonstrate 1 idea at a time, and finish up being too simplistic or trivial.

I haven't read a lot of text books that cover the whole language, most of my books are more specific, like Algorithms & Data Structures.

Some things that are done badly include the use of using namespace std;; not putting class declarations into headers, and definitions into .cpp files; putting all the code in 1 file;having get / set functions for each member variable; and having examples that are too small; plus many others.

All these things are done because that is the simplest thing, but not the best or most elegant. The problem is that newbies see these bad examples and then expand them big time, and wonder why they have problems. It is not helped by teachers who tell their students to provide get / set functions for each member variable. Of course it is not all the teachers fault, somehow the students get the basics all screwed up.
TheIdeasMan wrote:
Well I believe Kernighan & Ritchie - the inventors of the C language. Bjarne Stroustrup the inventor of C++ does it too.

Take a look at Stroustrup's code yourself:

http://www.stroustrup.com/vector35.c or other programs in http://www.stroustrup.com/3rd_code.html
Last edited on
There is no right or wrong here, just preference. However, that being said, I prefer forward declarations when I read someone else's code or my own, regardless of where they appear in the program.

Yes, main should technically have it's own file, but if you're going off of that rule, so should every function you create. Oh, not to mention that each of those files should also be broken into declarations in header files and definitions into source files. You have just turned one file example into 9 (for this basic program). So, I'm not sure I agree with that logic.

I agree that, yes having a prototype and definition creates more chances for error and more work overall, but I believe it keeps the code cleaner. The concept all goes back to classes for me. If class A has a pointer to a B object, and class B stores A objects, you need to at least declare them before defining them. This is a practice that's translated to the functions as well.

Just because you work at a programming job, I assume, doesn't mean you're practicing the best programming style either. I've seen code produced by hobbyist be much better than 6 figure salaried programmers.

I take a lot of my coding practices from Stroustrup, but that's how I learned to code, not because of him. The fundamentals of programming are taught early on, and you might pick up some bad habits (Read: using namespace std;) or some good ones (Read: proper indentation and code readability). But nonetheless, we can all learn from each other, we just need to be constructive with our criticism and not be so rough on each other.

Remember, we're coders, our goal should be to share what we know to help others and improve their skills so that someone may do it in return. Not one person in the world knows everything there is to know about C++ so we should take all advice productively.
I'm using visual studio basic to do my programming but idont know why it doesn't debug
I really don't know how to deal with this program..
Have you made the changes required for it to compile?
Hi jenny22,

If your program does not compile, then post the compiler output in full - we can help from there.
I'm using visual studio basic to do my programming but idont know why it doesn't debug


As TheIdeasMan already asked - what do you mean by "It doesn't debug"? What errors are you getting?
Last edited on
Its not just debugging ....but it does compile ...and shows no error!!
You guys think this one will work?
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
#include<iostream> 

#include<string>

using namespace std;


const double package a = 9.95;

const double package b = 14.95;

const double package c = 19.95;



            
double Amount(string&, int);                                

void displayOutput(string,double,int,double,double)            



void inputData(string& name ,double& initial_balance ,char& package,int& num_checks)

    {

        cout<< "\nEnter name: ";  

            getline(cin,name);               
                    

        cout<< "\nEnter type of package: ";             

        getline(cin, package);                             

        cout<< "\nEnter number of checks: ";  

        getline(cin,num_checks);

        return;

    }



int main()

{


      string name;

      char package;

      int num_checks;

      double initialbalance,newbalance, costpackage, feetotal=0.0;
      
      //program statements.

        inputData(intname,int initialbalance, intpackage,int numchecks)


         

        if (package = A) 

           cost Package=package a; 

        else if (package = B)    

           cost Package= package b;

        else if (package = C)

           cost Package= package c;

        else if

        {

            cout << "\nPlease enter a valid package A, B or C"<<endl; 

            return 0;

        }

        fee_total= feeAmount(package,num_checks);


        new_balance= initial_balance - fee_total;        


        displayOutput(float name,initial_balance,package,num_checks,cost_package,new_balance)

    

    return 0;

}    

  

    double feeAmount(char package,int num checks) 

    {

        double cost_package,fee_total;

        double fee_checks=0;        

        if  (package=A)

        {

            cost package = package a;

                if (num checks>10)
        

                    fee checks= (num checks - 10)*0.2;


            fee total= cost package + fee checks;

        }

        else if (package=B)

        {

            cost package = package b;

                if (num checks>20)

                {

                    fee checks=(num checks - 20)*0.1;

                }

            fee total= cost package + fee checks;

        }

        else if

        {

            cost package = package c;

            fee total =costPackage;

        }

        return fee total;

    }


      void displayOutput(string name,double initial balance, char package,int num checks,double cost package,double new balance)

      {

         

         cout<<setiosflags(ios::fixed) <<setiosflags(ios::showpoint)    

              << setprecision(2)

        

        

         cout<<"\t\t__________________________________________________\n"

             <<"                                                      \n"

             <<"\t\t         Siegel    Passaic     Bank               \n"<<endl<<endl;

        

         cout<<"\t\tAccount Summary"<<endl;

         cout<<"\t\t---------------"<<endl<<endl;

         cout<<"\t\tName: "<<setw(45)<<name << endl;

         cout<<"\t\tInitial balance: "<<setw(21)<<'$'<<initial balance << endl;

         cout<<"\t\tPackage: "<< setw(35)<<"Package"<<package<< endl;

         cout<<"\t\tChecks: "<<setw(31)<<num_checks<< endl;

         cout<<"\t\tFee package: "<<setw(25)<<'$'<<cost package<< endl;

         cout<<"\t\tNew balance: "<<setw(25)<<'$'<<new balance << endl<<endl ;

        

          if (new_balance<200)

            cout<<setw(10)<<right<<"\n"<<"\t\tWarning: Balance too low"<<endl;

         cout<<"\t\t__________________________________________________\n"<<endl<<endl;

         return;

           }  
There's one way to find out...
I tried to open up in visual basic but still shows some error...please fix it :)
I got it fixed !!!
Topic archived. No new replies allowed.