![]() |
|
#1
|
|||
|
|||
Just starting C++I'm taking an introductory c++ course at my university; our project this week is a program that calculates a shipping/merchandise cost for sales. I'm not a computer science major or anything, so I have very little programming background. I've included comments that hopefully explain what each function is supposed to do. I've also included the compile errors below. I haven't written all of the functions, because I'm stuck on the compile errors.
CPP / C++ / C Code:
wholeSale_.cpp: In function `int main()': wholeSale_.cpp:28: error: `ordered' was not declared in this scope wholeSale_.cpp:29: error: invalid conversion from `int (*)()' to `int' wholeSale_.cpp:29: error: initializing argument 1 of `int backorder(int, int)' wholeSale_.cpp:29: error: invalid conversion from `int (*)(int, int)' to `int' wholeSale_.cpp:29: error: initializing argument 2 of `int backorder(int, int)' |
|||
|
#2
|
|||
|
|||
Re: Just starting C++lol, soo many functions...
I'll take it bit by bit CPP / C++ / C Code:
there shouldn't be anything before #include (not at this level at least), make sure to delete everything before #include. next bit is hard to explain on your code so I'll make a new example CPP / C++ / C Code:
when I declared variable, it's availability domain is just function, and outside fuction, it doesn't exist. In your program since you keep using the same variables, I suggest 1. using global variables (declare them outside of functions, and they will be available everywhere) 2. since all your code is liniar, you can just write it in main, without the use of so many functions 3.keep some exchange variables in main, like CPP / C++ / C Code:
I think the other errors are caused by the inavailability of the variables, try using one of my suggestions and post again. Hope this helps |
|
#3
|
||||
|
||||
Re: Just starting C++Quote:
Compare your code to the following: CPP / C++ / C Code:
...while this compiles "cleanly," it doesn't perform as you probably intend. Part of your problem started with the very first line where you have an opening brace. Then you tried to pass a function address (function pointer) as an integer value to a couple of functions, which is obviously not what you intended. My changes include adding a couple of variables (not globals!) to hold the results of your program flow that fetches information from the user. Also, you do not want to specify a function that returns a value without actually returning a value. Increase your warning level using the following: g++ -g -Wall -W -pedantic -o wholeSale_ wholeSale_.cpp The -g switch enables debugging symbols. You will certainly want to use a debugger in your development process. A better idea is to write a main that does nothing but return a zero. Compile it and test it. Add a very small bit of functionality, compile, execute/test, debug. Keep going by adding a very small bit of new functionality each time. By adding a whole bunch of "stuff at one time" you risk not ever knowing what part is causing issues. Better is to build incrementally on small successes, particularly until you get the hang of things. So, in your code, you would have found that the first call in main to "spoolssent" would have blown up...because that would have been the "next" thing that you added as the others would have succeeded (assuming you removed the brace on the first line). Then you would have known to investigate that one line and resolve it before continuing. As pointed out by a previous poster, variable names of "a, b, c" are rarely a very good choice. If you're writing a program that works with trigonometry, they're probably useful, meaningful names. Just about everywhere else, they're going to be much less indicative of the thinking (or lack thereof) that went into their declarations. While commonplace to newcomers, coding style issues tend to be plentiful and lack good consistency. Here are a few style choices that you may want to consider employing very early on. I find that they help reduce bugs by making the code more consistent and easier to develop and maintain over time, which can be even a few minutes or much longer. 1: Always use "multi-line" style conditional statements (this means to add braces after every if..else..while, etc.), even if the next line is the only line, which would be a "single-line" conditional statement. 2: Find a reliable, common variable naming convention. Remember that your function names are "variables" in a sense, too. They are "variable" in the sense that they need to be descriptive and they need to be easy to read and that you're the one telling us about them for the first time, so come up with a naming convention that works. Plentiful examples abound. 3: Always use spaces between operators. That means, don't do a+b=c; Use a + b = c; instead. 4: Prefer to use more variables than fewer. If you are going to call a function that returns a value, declare a variable of the return type and store the result of the function call in that variable. 5: Step through your code with a debugger. While some prefer to use "cout" or "printf" almost exclusively, the benefit of using a debugger will greatly enable you should you ever do anything more than the most trivial coding. At the bare minimum, if you do #4 above, it is much easier to cout and printf your "status" as you execute code. Just remember, while cout/printf may be your "friends," they make code fatter, harder to maintain and dramatically increase required system resources and code execution time. On some platforms, this may be unimportant. On others, it is impossible. Develop a coding style (prefer a common style over your own, homegrown style choices) and stick with it...at least for now. Depart when you're ready and have some meaningful reason to change styles. At some future point, you may want to get used to coding using any of perhaps 5 to 7 of the most common coding styles. Being style agnostic is a good thing, as long as the style is consistently applied and doesn't "freak out" other programmers. MxB |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Starting own Web Design Small Business. | harypo | Web Design Forum | 3 | 12-Nov-2008 07:58 |
| cPanel Hosting starting at ONLY $3.95/mo - FREE SETUP - RVSkin & FANTASTICO | WireNine | Web Hosting Advertisements & Offers | 0 | 20-Feb-2007 09:59 |
| cPanel Hosting starting at ONLY $3.95/mo - FREE SETUP - RVSkin & FANTASTICO | WireNine | Web Hosting Advertisements & Offers | 0 | 13-Feb-2007 12:50 |
| Problem starting up with my Vaio | Vaio007 | Computer Hardware Forum | 1 | 06-Sep-2005 12:09 |
| Starting Mysql server problem | pjacks | MySQL / PHP Forum | 23 | 08-Sep-2004 17:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The