Posted: 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
Posted: Mon Feb 20, 2006 8:22 pm Post subject: (No subject)
You'll have to show us your code.
AnubisProgrammer
Posted: Mon Feb 20, 2006 8:27 pm Post subject: (No 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.
Posted: Mon Feb 20, 2006 10:15 pm Post subject: (No subject)
Where's your "main" function?
Justin_
Posted: Mon Feb 20, 2006 10:23 pm Post subject: (No 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.
Justin_
Posted: Mon Feb 20, 2006 10:26 pm Post subject: (No 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.
AnubisProgrammer
Posted: Mon Feb 20, 2006 11:23 pm Post subject: (No 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 . So, once again, thanks much.
wtd
Posted: Mon Feb 20, 2006 11:34 pm Post subject: (No subject)
Indeed. Things you need to work on:
Get rid of global variables. In your code this means "santacruz".
code:
struct santacruz_name{
int year, modelnumber;
}santacruz;
Learn how to use "else".
code:
if (santacruz.year == 2002){
t2002();
}
if (santacruz.year == 2003){
t2003();
}
if (santacruz.year == 2004){
t2004();
}
if (santacruz.year == 2005) {
t2005();
}
For the same code... Learn how to use "switch".
For that very same code... look at your code and look at my clean-up of it, and learn how to use spaces.
Don't use magic numbers. I have no idea what those numbers signify.
code:
santacruz.modelnumber>=330001
Sponsor Sponsor
AnubisProgrammer
Posted: Mon Feb 20, 2006 11:43 pm Post subject: (No 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.
wtd
Posted: Tue Feb 21, 2006 1:34 am Post subject: (No subject)
For the magic numbers, define constants instead.
code:
const int BLUE_WIDGET_Z_MODEL_NUMBER = 1234567;
Justin_
Posted: Tue Feb 21, 2006 4:27 pm Post subject: (No 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.
wtd
Posted: Tue Feb 21, 2006 4:43 pm Post subject: (No 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.
AnubisProgrammer
Posted: Tue Feb 21, 2006 9:36 pm Post subject: (No 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.
wtd
Posted: Tue Feb 21, 2006 9:48 pm Post subject: (No subject)
Well, you could have a type of data structure that holds:
Year
Model # Range Start
Model # Range End
Suggested Model #
Suggested Model #'s price.
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.
AnubisProgrammer
Posted: Tue Feb 21, 2006 9:51 pm Post subject: (No 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.