Join 136,173 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,947 people online right now. Registration is fast and FREE... Join Now!
well you DID say critique... So hold on (not trying to be mean).
First off lets talk about global variables: They really should not be used. Like many style "rule" this is not really a rule some much as a lesson. Over the years programmers have learned over and over that global variables can introduce wickedly hard to track down bugs. Especially when linked together with some of the other stylistic things I will mention.
Using the same name for different variables: You have used the variable name 'Transcode' in a number of places. First off it is in the global scope so if you are not carful with scoping you may change the variable in a local scope and have unintended consequences on the global variable (see the note above). Secondly it is inside a struct which is actually ok-ish since as a member of the struct it gets prefixed with the struct's variable name. Then you use it as an argument to Getdata()... but it is not passed by reference, and that is not the global... is that a bug I see already?
You use function names that are all caps: This is normally reserved for macro's. Over the years programmers found that macro's can be cause problems if the programmer does not keep in mind that they are macro's, to help mitigate this situation the convention is that macro's are named with all caps so that other programmers can instantly recognize them.
The style points above do not really make a huge difference, but they can make your life much more livable when there are problems.
well you DID say critique... So hold on (not trying to be mean).
First off lets talk about global variables: They really should not be used. Like many style "rule" this is not really a rule some much as a lesson. Over the years programmers have learned over and over that global variables can introduce wickedly hard to track down bugs. Especially when linked together with some of the other stylistic things I will mention.
Using the same name for different variables: You have used the variable name 'Transcode' in a number of places. First off it is in the global scope so if you are not carful with scoping you may change the variable in a local scope and have unintended consequences on the global variable (see the note above). Secondly it is inside a struct which is actually ok-ish since as a member of the struct it gets prefixed with the struct's variable name. Then you use it as an argument to Getdata()... but it is not passed by reference, and that is not the global... is that a bug I see already?
You use function names that are all caps: This is normally reserved for macro's. Over the years programmers found that macro's can be cause problems if the programmer does not keep in mind that they are macro's, to help mitigate this situation the convention is that macro's are named with all caps so that other programmers can instantly recognize them.
The style points above do not really make a huge difference, but they can make your life much more livable when there are problems.
So your saying it's a mess. I know because when I compile it kept bringing up errors then I would move a function or something and it would run but not how I planned for it to.
Which leads to a final note, objects? This code is begging for a class or two. You have three functions that process identical parameters, with the fourth differing in only a minor way. Any way to bring all that data together in a unified manner?
Which leads to a final note, objects? This code is begging for a class or two. You have three functions that process identical parameters, with the fourth differing in only a minor way. Any way to bring all that data together in a unified manner?
That's my question what can I do to make this program less combursome. Take something out or combine some functions. And I still have problems just opening my file. I get so confused but I want to understand. I am retaking this class next semester but I want to go in with a little knowledge of what I am doing. Help!
I really seems you're looking to deal with some kind of checkbook? Just maintaining a single transaction does not seem to be the way to go. Without creating any custom objects, but killing the globals, here's one way you could do it:
void Print(const TransCodeType transCode) { string s = ""; switch(transCode) { case OpeningBalance: s = "Opening"; break; case Check: s = "Check"; break; case Deposit: s = "Deposit"; break; case Atm: s = "Atm"; break; case AtmFee: s = "Atm Fee"; break; case ServiceFee: s = "Service Fee"; break; case Withdrawl: s = "Withdrawl"; break; } cout << left << setw(20) << s; }
I really seems you're looking to deal with some kind of checkbook? Just maintaining a single transaction does not seem to be the way to go. Without creating any custom objects, but killing the globals, here's one way you could do it:
void Print(const TransCodeType transCode) { string s = ""; switch(transCode) { case OpeningBalance: s = "Opening"; break; case Check: s = "Check"; break; case Deposit: s = "Deposit"; break; case Atm: s = "Atm"; break; case AtmFee: s = "Atm Fee"; break; case ServiceFee: s = "Service Fee"; break; case Withdrawl: s = "Withdrawl"; break; } cout << left << setw(20) << s; }