Computer Science Canada What causes this error? |
Author: | AnubisProgrammer [ Mon Feb 20, 2006 8:17 pm ] |
Post subject: | What causes this error? |
I'm doing a project for school, it's an idiotic program that someone in my class made up. Insane amount of if statements and such. However, I think there's a problem with my functions. I was just wondering what would cause these 2 errors? I'm calling my functions the same way I always do. No matter what I do I always get these errors. I'm using a win32 console application, same as I always do. Anyways, these are the two errors I'm getting when I compile. Any points or advice would be helpful LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/Santa Cruz.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. |
Author: | wtd [ Mon Feb 20, 2006 8:22 pm ] |
Post subject: | |
You'll have to show us your code. |
Author: | AnubisProgrammer [ Mon Feb 20, 2006 8:27 pm ] |
Post subject: | |
My code is 170 lines long and not properly set up. It's incredibly unorganized with very long if statements. I'll attach the cpp file because to post my code would take to much space. I think I posted the right code. My functions should be called t2002, t2003 and so forth (bad names because I was attempting to debug and change names around. Anyways, this is my code, such as it is. |
Author: | wtd [ Mon Feb 20, 2006 10:15 pm ] |
Post subject: | |
Where's your "main" function? |
Author: | Justin_ [ Mon Feb 20, 2006 10:23 pm ] |
Post subject: | |
i heard there's a way to change your programs entry point, i forget how its done but its fairly simple. I think his entry point is: santa_cruz() and he was right, that is an idiotic program and even if i dedicated 20 minutes to go through the code i'd still probably not find why it won't compile. |
Author: | Justin_ [ Mon Feb 20, 2006 10:26 pm ] |
Post subject: | |
nevermind, the reason the program won't compile is specifically because it doesn't have an entry point ![]() just add a main() function to call upon your santa_cruz there man. It compiles fine. |
Author: | AnubisProgrammer [ Mon Feb 20, 2006 11:23 pm ] |
Post subject: | |
ya, I've realized the problem. It's a group assignment so everyone's writing a certain chunk of the code. My function was santa_cruz. I changed the name from main too soon. Right, thanks a lot. And ya, I realize that the code I posted there was extremely disorderly and such. But I was doing it on a time schedule and had just learned how to use structs ![]() |
Author: | wtd [ Mon Feb 20, 2006 11:34 pm ] | ||||||
Post subject: | |||||||
Indeed. Things you need to work on:
|
Author: | AnubisProgrammer [ Mon Feb 20, 2006 11:43 pm ] |
Post subject: | |
Alright, I've decided that I most definately do need to learn the switch statement, I've been working on it, it's simple, but I didn't really want to test it out on a group project. Else statements are something I never really got into, but they'd probably make my code neater. As for the magic numbers, they represent the model number of a bike. The entire code was supposed to have the user input a Company, then a model year, then a model number and tell them if their bike was defective or not. Then it was to bring up a list of suitable replacements. Same company, same year, equal or lesser price. Anyways, I need to finish up my code, so I'm out of here. Thanks a lot for the help, as well as the "areas to improve on" I'll definately try to use some of those ideas. |
Author: | wtd [ Tue Feb 21, 2006 1:34 am ] | ||
Post subject: | |||
For the magic numbers, define constants instead.
|
Author: | Justin_ [ Tue Feb 21, 2006 4:27 pm ] |
Post subject: | |
Yeah using constants instead of those long numbers that an outsider wouldn't know anything about helps to make the code more understandable and, in my oppinion, pretty lol. And just for the record dude, its not like using switch statements is rocket science. Just read about them, you'll understand it easy, then apply them and you'll never forget them. |
Author: | wtd [ Tue Feb 21, 2006 4:43 pm ] |
Post subject: | |
One more thing... let's look at your functions "t200x". What exactly makes them different? They check to see if the model number falls into a particular range, and if so describe alternatives. You have this hard-coded in, but you could store that information in data structure and make your program much more flexible. |
Author: | AnubisProgrammer [ Tue Feb 21, 2006 9:36 pm ] |
Post subject: | |
I'm not sure I understand. If I used a struct for the year wouldn't I still need the functions? I'm sorry for asking this many questions, but I find the answers I get here are the most helpful. |
Author: | wtd [ Tue Feb 21, 2006 9:48 pm ] |
Post subject: | |
Well, you could have a type of data structure that holds:
Then if you had an array of such data structures, you could loop over it, find the structure that matches your criteria, and get the relevent information from it. |
Author: | AnubisProgrammer [ Tue Feb 21, 2006 9:51 pm ] |
Post subject: | |
I think I see what you're saying...that most likely would have made my code easier. Unfortunately I'm fairly new to arrays as well so they're not the first idea that come to mind when I'm working out how to solve a problem. I'll have to keep them in mind though. Until I learn vectors anyways. |
Author: | Justin_ [ Tue Feb 21, 2006 11:28 pm ] |
Post subject: | |
my suggestion Anubis is that you avoid writing repitious code. It makes you feel like you know what your doing maybe but all it is is you being stuck in your ways and not wanting to learn new stuff. Just keep learning, do some examples, but never over do it. Writing a series of if statements does not mean you can program. |
Author: | wtd [ Tue Feb 21, 2006 11:57 pm ] |
Post subject: | |
Indeed. A serious problem with CS education, at least at the HS level seems to be that assignments are not carefully developed to teach a specific set of important skills. |
Author: | AnubisProgrammer [ Wed Feb 22, 2006 3:18 pm ] |
Post subject: | |
I agree Justin_. This program was designed by a student in the class (my teacher is making two students make up the assignments). It was designed for if statements. I thought it was a little overkill and very redundant. And yes, the assignments we get don't specify what we're supposed to learn from them. They just tell us to do it. It really sucks. But, might as well try and develop the basics in class, then learn new things on my own time. |