| zeta4321 (13) | ||||
|
Hey everyone, I'm working on a homework problem for my computer science class, and I'm running into a few issues. These issues exist primarily within my function responsible for validating codes that are read in from a text file. Additionally, I'm having issues calling my validation function within my mainline logic. I would greatly appreciate any help/clarification/guidance you guys could provide. Thanks in advance! I apologize in advance for the big block of code! P.S. I'm including the codes that I am using in my input file for your convenience. The Codes to be Validated
My Program
| ||||
|
Last edited on
|
||||
| jlb (77) | |
| You may want to think about using functions to simplify your code. Possibly a function that validates each of your three valid lengths. | |
|
|
|
| zeta4321 (13) | |||
|
Okay, I've taken your advice, and I've now created 4 separate functions that handle my validations. However, within my IDE, I keep getting errors in terms of my brackets saying that it is "expecting a declaration." I would appreciate it if I could get some clarification. Thanks! P.S. Please note that my mainline logic has not changed at this point. If you'd like to look at that, it's in the original post.
| |||
|
Last edited on
|
|||
| Zereo (181) | |
| Dont mean to sound rude or anything either but you might also want to reconsider your indentation on your code. I know everyone has there own style that works for them, but when other read your code and it is to long or to many space/indentations it makes it hard to work on and or debug. It is almost never a good thing to have your code go off the page horizontally. | |
|
|
|
| Chervil (806) | |
| Well, not just indentation, but also the insertion of line breaks would be beneficial, to keep the code within the width of the screen. | |
|
|
|
| jlb (77) | |
|
Also after you fix your indentation, and line breaks, if you are still getting errors, post the complete error messages, exactly as they appear in your development environment. Make sure these errors match the code you post. | |
|
|
|
| zeta4321 (13) | |
|
@Brandon Sorry about the formatting issues! I've tried to make it look more legible. | |
|
|
|
| zeta4321 (13) | |||
|
Everyone, Sorry about the formatting issues! I've tried to make it look more legible. Please note that the code for my validation does occur as a long chain, so it will probably need to be put back into one long statement. The code is now as follows:
For my program, I am using Visual Studio 2010. I have 6 total errors, all of them stating "IntelliSense expected a declaration." These errors occur on lines 109, 114, 122, 124, 129, and 149. | |||
|
|
|||
| jlb (77) | |
|
For the error on line 109, check line 107. It appears you have an errant semicolon at the end of this line. Also "IntelliSense" errors are not compiler errors. You need to post the complete compiler errors exactly as they appear in your development environment. For the rest of your errors you may want to see if you have more errant semicolons. | |
|
|
|
| cire (1845) | |||
You might consider the following:
| |||
|
|
|||
| zeta4321 (13) | |||
|
@cire You are awesome! Thank you so much! I ran your code, and it worked flawlessly! One last question: how would I integrate outputting to a file within the code you have written? Unfortunately, I am only familiar with the "using namespace std;" method, and I'm not exactly sure how to integrate ifstream, ofstream, .open, and .close. I would be most grateful if you could please explain how I would need to integrate those capabilities. Thanks again! Here is my attempt at getting the valid codes to output to a file called "valid.txt" and the erroneous codes to output to a file called "errors.txt"
I receive errors on lines 46 and 48 occur at the "<<" between ofstream and input. I get an error from my compiler that reads "Error: expected a ';'" How do I go about correcting this problem? | |||
|
Last edited on
|
|||
| cire (1845) | |
|
out and out2 are defined on lines 37 and 39. On lines 46 and 48 you don't need the type (std::ofstream,) just the object name. | |
|
|
|
| zeta4321 (13) | |
|
Awesome! The code works beautifully! Thanks again! | |
|
|
|